1

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?

yolo
  • 2,757
  • 6
  • 36
  • 65
  • 4
    What error messages do you get, and on which lines? – Oliver Charlesworth Aug 31 '11 at 11:31
  • Why can't you use the [] notation with `unsigned char*`? – duedl0r Aug 31 '11 at 12:16
  • gives exc_bad_access on that line – yolo Aug 31 '11 at 12:20
  • Please update your question to make it more clear. First, you are assigning an `unsigned char*` to a `char *`, which causes a compiler error about incompatible types. Then, if you declare mem as `unsigned char *` your code will be formally correct, but causes _exc_bad_access_ **when running**. This means that you can't access an arbitrary memory region from within a userland process. Look for physical and virtual memory addresses and how to handle them in userland processes. – amso Sep 01 '11 at 08:58
  • i found that this was incorrect method for my system, i dont need it any more! – yolo Sep 01 '11 at 10:18

2 Answers2

2

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.

Christopher Creutzig
  • 8,656
  • 35
  • 45
0

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

yolo
  • 2,757
  • 6
  • 36
  • 65