[C.C++] 写一个陷阱门的测试程序

1786 2
狼毛 2023-8-23 21:35:36 | 显示全部楼层 |阅读模式
  1. //写一个陷阱门的测试程序
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include <errno.h>
  7. #include <signal.h>
  8. #include <sys/types.h>
  9. #include <sys/wait.h>
  10. #include <fcntl.h>
  11. #include <sys/stat.h>
  12. #include <sys/mman.h>
  13. #include <semaphore.h>
  14. #include <pthread.h>
  15. #include <sys/socket.h>
  16. #include <netinet/in.h>
  17. #include <arpa/inet.h>
  18. #include <netdb.h>
  19. #include <sys/time.h>
  20. #include <sys/resource.h>
  21. #include <sys/ipc.h>
  22. #include <sys/msg.h>
  23. #include <sys/shm.h>
  24. #include <sys/sem.h>
  25. #include <sys/uio.h>
  26. #include <sys/select.h>
  27. #include <sys/time.h>
  28. #include <sys/un.h>


  29. int main(int argc, char *argv[])
  30. {
  31.     int fd;
  32.     int ret;
  33.     int i;
  34.     int count;
  35.     int *p;
  36.     int *q;
  37.     int *r;
  38.     int *s;
  39.     int *t;
  40.     int *u;
  41.     int *v;
  42.     int *w;
  43.     int *x;
  44.     int *y;
  45.     int *z;
  46.     int *aa;
  47.     int *bb;
  48.     int *cc;
  49.     int *dd;


  50.     fd = open("trapdoor", O_RDWR);
  51.     if(fd < 0)
  52.     {
  53.         perror("open");
  54.         return -1;
  55.     }
  56.     p = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  57.     if(p == MAP_FAILED)
  58.     {
  59.         perror("mmap");
  60.         return -1;
  61.     }
  62.     q = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 4096);
  63.     if(q == MAP_FAILED)
  64.     {
  65.         perror("mmap");
  66.         return -1;
  67.         }
  68.         r = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 8192);
  69.         if(r == MAP_FAILED)
  70.         {
  71.             perror("mmap");
  72.             return -1;
  73.          }

  74.          s = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 12288);
  75.                  if(s== MAP_FAILED)
  76.         {
  77.             perror("mmap");
  78.             return -1;
  79.          }
  80.          t = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 16384);
  81.                  if(t== MAP_FAILED)
  82.         {
  83.             perror("mmap");
  84.             return -1;
  85.          }

  86.          u = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 20480);
  87.                  if(u== MAP_FAILED)
  88.         {
  89.             perror("mmap");
  90.             return -1;
  91.          }
  92.          v = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 24576);
  93.                  if(v == MAP_FAILED)
  94.         {
  95.             perror("mmap");
  96.             return -1;
  97.          }
  98.          w = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 28672);
  99.                  if(w == MAP_FAILED)
  100.         {
  101.             perror("mmap");
  102.             return -1;
  103.          }
  104.          x = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 32768);
  105.                  if(x == MAP_FAILED)
  106.         {
  107.             perror("mmap");
  108.             return -1;   
  109.          }
  110.          y = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 36864);
  111.                  if(y == MAP_FAILED)
  112.         {
  113.             perror("mmap");
  114.             return -1;
  115.          }
  116.          z = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 40960);
  117.                  if(z== MAP_FAILED)
  118.         {
  119.             perror("mmap");
  120.             return -1;
  121.          }
  122.          aa = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 45056);
  123.                  if(aa == MAP_FAILED)
  124.         {
  125.             perror("mmap");
  126.             return -1;
  127.          }
  128.          bb = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 49152);
  129.                  if(bb == MAP_FAILED)
  130.         {
  131.             perror("mmap");
  132.             return -1;
  133.          }
  134.          cc = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 53248);
  135.                  if(cc== MAP_FAILED)
  136.         {
  137.             perror("mmap");
  138.             return -1;
  139.          }
  140.          dd = (int *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 57344);
  141.                  if(dd == MAP_FAILED)
  142.         {
  143.             perror("mmap");
  144.             return -1;
  145.          }
  146.          count = 0;
  147.          while(1)
  148.          {
  149.              *p = count;
  150.              *q = count;
  151.              *r = count;
  152.              *s = count;
  153.              *t = count;
  154.              *u = count;
  155.              *v = count;
  156.              *w = count;
  157.              *x = count;
  158.              *y = count;
  159.              *z = count;
  160.              *aa = count;
  161.              *bb = count;
  162.              *cc = count;
  163.              *dd = count;
  164.              count++;
  165.              sleep(1);
  166.              printf("count = %d\n", count);
  167.              if(count == 1000)
  168.              {
  169.                  break;
  170.                  }
  171.                  }
  172.                  return 0;
  173.                  }












复制代码

AWS Toolkit挺好用的。免费的代码提示AI。

开朗的盟员 2023-8-23 22:37:24 | 显示全部楼层
看看我,打赏20

点评

谢谢啦  详情 回复 发表于 2023-8-24 19:14
狼毛 2023-8-24 19:14:58 | 显示全部楼层

谢谢啦
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

狼毛

精英红客

关注
  • 206
    主题
  • 2
    粉丝
  • 1
    关注
这家伙很懒,什么都没留下!

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行