Page 1 of 1

Looking for a string in memory

Posted: Sun Mar 02, 2008 9:03 am
by AlfaOmega08
In the SMBIOS Specification, is written that the SMBIOS table starts with the "_SM_" string.
Now, I need an algorithm to find this string in memory.

I've tried with:

Code: Select all

int *mem;
mem = (int *) 0xF0000;

while (*mem < 0xFFFFF) {
	if (*mem == '_') {
		monitor << "Found a '_'";
		i++;
	}
	*mem++;
}
But it didn't work. It doesn't find any "_";
How can I find all the string???

Posted: Sun Mar 02, 2008 9:55 am
by Ready4Dis
Where to start...

Code: Select all

char *mem = (char*)0xF0000;
while (mem < 0xFFFFF) //mem == addr of mem, *mem = data stored at pointed to location!
{
  if (mem[0] == '_' && mem[1] == 'S' && mem[2] == 'M' && mem[3] == '_')
 {
  monitor << "Found it!"
  break;
 }
 mem+=4;  //Is it 4 byte aligned, then increment by 4 instead, or whatever alignment it has
}
The other way you can do is like this (assuming 4-byte alignment)

Code: Select all

uint32 *mem (uint*)0xF0000;  //32-bit unsigned...
uint32 val = ('_'<<24) + ('M'<<16) + ('S'<<8) + '_'; //Make dword
while  (mem < 0xFFFFF)
{
 if (*mem == val)
 {
   monitor << "Found it";
 }
 ++mem; //Increments mem by 4-bytes since it's a 32-bit int!
}

Posted: Sun Mar 02, 2008 10:25 am
by AlfaOmega08
Each method give me error on the while line:
error: ISO C++ forbids comparison between pointer and integer

Posted: Sun Mar 02, 2008 10:30 am
by cyr1x
You should know how to fix this problem if you know the language properly.
Please learn your language first before you tackle something like an operating system.
But anyway here's the fix:

Code: Select all

while ((unsinged int)mem < 0xFFFFF) 

Posted: Sun Mar 02, 2008 10:56 am
by AlfaOmega08
Ok now it works (on vmware not on bochs)

Thanks