Looking for a string in memory

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Looking for a string in memory

Post 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???
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post 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!
}
User avatar
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Post by AlfaOmega08 »

Each method give me error on the while line:
error: ISO C++ forbids comparison between pointer and integer
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post 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) 
User avatar
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Post by AlfaOmega08 »

Ok now it works (on vmware not on bochs)

Thanks
Post Reply