在内存中搜索字符串
我正在尝试让此代码正常工作,来自 此处
char *mem = (unsigned char *) 0xF0000;
int length, i;
unsigned char checksum;
while ((unsigned int) mem < 0x100000) {
if (mem[0] == '_' && mem[1] == 'S' && mem[2] == 'M' && mem[3] == '_') {
length = mem[5];
checksum = 0;
for(i = 0; i < length; i++) {
checksum += mem[i];
}
if(checksum == 0) break;
}
mem += 16;
}
有一些类型错误,例如 cant使用 unsigned char* 初始化 char*。
当我尝试将 char *
替换为 unsigned char *
int 第一行时,我无法使用 [] 表示法,如何在此代码中使用 memcmp
?
I'm trying to get this code to work, from here
char *mem = (unsigned char *) 0xF0000;
int length, i;
unsigned char checksum;
while ((unsigned int) mem < 0x100000) {
if (mem[0] == '_' && mem[1] == 'S' && mem[2] == 'M' && mem[3] == '_') {
length = mem[5];
checksum = 0;
for(i = 0; i < length; i++) {
checksum += mem[i];
}
if(checksum == 0) break;
}
mem += 16;
}
There are some type errors, like cant init char* with unsigned char*.
when I try to replace char *
with unsigned char *
int first line I cant use [] notation, how can I use memcmp
with this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第一行中,您转换为
unsigned char*
,但尝试分配给char*
。为什么不直接转换为char*
?我假设您正在处理一些嵌入式系统代码,因为在多任务操作系统中,仅访问硬编码的内存位置就会导致程序崩溃。
In the first line, you cast to
unsigned char*
, but try assigning tochar*
. Why not cast tochar*
directly?I'm assuming you are working on some embedded system code, since with multitasking operating systems, simply accessing hard-coded memory locations will cause your program to crash.
该代码无法工作,因为在 EFI 机器上查找 smbios 入口点结构地址的方法不正确,
The code failed to work because it is incorrect way of finding smbios entry point structure address on an EFI machine,