zoukankan      html  css  js  c++  java
  • 在一段内存中查找数据

    #include <stdio.h>
    
    
    char code[] = 
                {
                0x64,0x10,0x00,0x00,0x20,0x64,0x00,0x01,0x00,0x80,
                0x01,0x90,0x08,0x07,0x20,0x64,0xa0,0x00,0x03,0x80,
                0x01,0x90,0x08,0x07,0x20,0x64,0x00,0x08,0x00,0x03,
                0x01,0x07,0x20,0x64,0x64,0x00,0x00,0x00,0x03,0x80,
                0x01,0x90,0x08,0x64,0x64,0x00,0x00,0x00,0x03,0x80,
                0x01,0x90,0x08,0x64,0x00,0x00,0x00,0x00,0x00,0x80,
                0x01,0x90,0x64,0x00,0x00,0x00,0x07,0x20,0x03,0x80,
                0x01,0x64,0x00,0x00,0x00,0x20,0x07,0x20,0x64,0xa0,
                0x01,0x90,0x64,0xa0,0x00,0x03,0x80,0x00,0x03,0x80,
                0x01,0x64,0x00,0x01,0x00,0x64,0x01,0x00,0x00,0x80
                };
    
    int main()
    {
    
        int* cp = (int*)code;
        char* cp1 = code;
        for(int i = 0; i < 100; i++)
        {
            if(*cp == 0x64)
            {
                printf("%0x
    ",&cp[i]);
            }
            cp = (int*)(cp1+i+1);//在最后4个字节的时候,需要判断否则超出的100个字节
            
        }
        return 0;
    }

    查找data中的所有int类型值可能为0x64的地址,由于我们不知道哪四个字节组成才是int,所以只能计算每次地址偏移一个字节的int类型是否为x64.其他类型也是一样方法

  • 相关阅读:
    NOIp2018集训test-9-23
    NOIp2018集训test-9-22(am/pm) (联考三day1/day2)
    NOIp2018集训test-9-21(am/pm)
    NOIp2018集训test-9-19(am&pm)
    day41.txt
    day40表关系
    day39
    day38数据库
    day37
    day36
  • 原文地址:https://www.cnblogs.com/zheh/p/4558896.html
Copyright © 2011-2022 走看看