从缓冲区读取数据! [英] Reading Data From Buffers!!

查看:108
本文介绍了从缓冲区读取数据!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我们可以在不知道其DATATYPE的情况下从带有地址的缓冲区读取数据并在控制台上打印该数据吗?
例如我有一个缓冲区89F25F30的地址.现在,我想从此缓冲区读取数据.我也不知道数据的数据类型.之后,我想在控制台上打印该数据. (我正在Windows平台上工作)

现在告诉我有可能吗?如果是,怎么办?
请帮助我.这只是我项目的最后一步.

谢谢大家
Naveen Kumar Dushila

Hello Friends,

Can we read data from a Buffer with its Address and Print that data on the Console Without knowing its DATATYPE??
e.g. I have an Address of a Buffer 89F25F30. Now I want to read data from this buffer. I don''t know the datatype of data too. After that I want to print that data on the console. (I am working on windows platform)

Now tell me is it possible or not? If yes, how?
Please Help me out of this. Its just Last Step of my project.

Thank you all
Naveen Kumar Dushila

推荐答案

嗨 纳文

您可以以二进制或十六进制或ascii或deciman或任何其他格式打印该缓冲区.
Hi Naveen

You can print that buffer in binary or hex or ascii or deciman or any other format.


您好 纳文

您可以以二进制或十六进制或ascii或deciman或任何其他格式打印该缓冲区.

喜欢:-
Hi Naveen

You can print that buffer in binary or hex or ascii or deciman or any other format.

like:-
int x = 0x12345678;
int buffLen = 4; // you can set it according to your buffer length.
unsigned char *p = (unsigned char *)&x; // you can use here your buffer's address instead of &x
for(int i = 0; i < buffLen; i++)
{
    printf("\n Value at location \t%X is\t%X", p, *p);
    p++;
}

// warning this may cause segmentation fault.


好吧,我们可以肯定地从缓冲区读取数据:).我们需要的是缓冲区起始地址及其大小.只需将缓冲区起始地址分配给void *或char *或byte *(在需要时使用强制转换)就可以了.
但是,打印缓冲区并不是那么简单.您必须决定要查看的输出格式.您想以一种编码(ASCII,Unicode等)将缓冲区解释为字符数组吗?还是您至少不在乎输出是否有意义?在第一种情况下,您可以自由使用 printf() function或stdout.否则... printf()可以再次为您提供帮助:以十六进制形式写出缓冲区,您也可以使用它,以 ^ ](我想您需要使用类似的内容
Well, we can read data from a buffer, that''s for sure :). What we need is buffer start address and its size. Just assigning buffer start address to void* or char* or byte* (using cast when needed) is enough.
Printing your buffer out is not that straightforward, however. You must make decision on the output format you would like to see. Would you like to interpret your buffer as array of chars in one of encodings (ASCII, Unicodes etc)? Or you don''t care about your output having meaning at least sometimes? In the first case you''re free to use printf() function or stdout. Otherwise... well, printf() can help you again: to write your buffer out in hex you can use it too, printing byte by byte, in a manner described here[^] (I guess you''d need to use something like
printf("%X", (unsigned char)array_item[i]);




or

printf("%hhX", (char)array_item[i]);


)


这篇关于从缓冲区读取数据!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆