码迷,mamicode.com
首页 > 其他好文 > 详细

在一段内存中查找数据

时间:2015-06-07 20:04:53      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

#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\n",&cp[i]);
        }
        cp = (int*)(cp1+i+1);
        
    }
    return 0;
}

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

在一段内存中查找数据

标签:

原文地址:http://www.cnblogs.com/zheh/p/4558896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!