yolo
yolo

Reputation: 2795

Search for a string in memory

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?

Upvotes: 1

Views: 4837

Answers (2)

yolo
yolo

Reputation: 2795

The code failed to work because it is incorrect way of finding smbios entry point structure address on an EFI machine,

Upvotes: 0

Christopher Creutzig
Christopher Creutzig

Reputation: 8774

In the first line, you cast to unsigned char*, but try assigning to char*. Why not cast to char* 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.

Upvotes: 2

Related Questions