LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2008, 05:51 AM   #1
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 366
Blog Entries: 1

Rep: Reputation: 44
Scanning memory range for specific bytes w/ GDB


Is there a way to use gdb to scan a process' memory for a set of values in a specified address range?

For instance, if the heap for my process ran from 0x08050000 - 0x0827d000, and I wanted to have gdb return the address of the first location it finds within that address range which contains the 4-byte sequence 0xa17ad376 ... what is the command to do this sort of thing?

If GDB cannot do this, could someone recommend a tool that does possess this capability?

Thanks,
jrtayloriv
 
Old 03-14-2008, 03:47 PM   #2
arkinrome
LQ Newbie
 
Registered: Mar 2008
Location: México
Distribution: Slackware
Posts: 15

Rep: Reputation: 1
Yes you can inspect your memory with gdb look a this page for help..

You just have to type the command like: x/2b 0x8048382, of course you should have permissions over the address.

Cheers.

Last edited by arkinrome; 03-14-2008 at 04:04 PM.
 
Old 03-15-2008, 04:34 AM   #3
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 366

Original Poster
Blog Entries: 1

Rep: Reputation: 44
Thank you for the link. But I already knew about using x addr to see the value held at addr.

What I was asking for was how to scan a range of memory for a specific value -- i.e. I'd like to be able to do something like:

mystery_search_command 0x08050000,0x0827d000 0xa17ad376

to do what I described in my original post.

Is there a way to do this?

--jrtayloriv
 
Old 03-15-2008, 07:28 PM   #4
arkinrome
LQ Newbie
 
Registered: Mar 2008
Location: México
Distribution: Slackware
Posts: 15

Rep: Reputation: 1
Sorry I didn't understand the question, well right now I can only come up with somenthing like this: supose you know the address you want to start with, in gdb you tell it this:

(gdb) set $x=0xbfeff9a0
(gdb) while(*++$x!=0x14 && $x<0xbfeff9a9)
>end
(gdb) p/x $x

here at the example in looking for the 0x14 in memory, and p/x will give me the addres where it was found or the end address, I hope it can be useful now.

Regards.

Last edited by arkinrome; 03-15-2008 at 08:02 PM.
 
1 members found this post helpful.
Old 03-16-2008, 09:19 PM   #5
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 366

Original Poster
Blog Entries: 1

Rep: Reputation: 44
Hmmm ... very good idea. I didn't think of looping through w/ the convenience variables like that. Thanks for the tip

--jrtayloriv
 
Old 03-17-2008, 02:27 PM   #6
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
I have a file of C functions for doing complex things inside of GDB.
All of them are set up with do-nothing defaults, so when called they do not affect program behavior. (I do not have one for finding a memory value the way you specified. You also didn't indicate if the value was word-aligned or not. Makes a big difference in how you search.) I set up a single entry point in the code to force the linker to include them.

They do nothing. Unless.

You call the function in gdb "call functionname", with an already set breakpoint inside the function, change the arguments with set, and let it run. IF you need this often consider writing a simple
 
1 members found this post helpful.
  


Reply

Tags
gdb, memory, range, scan


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting by date a specific range of files nooks12 Linux - Newbie 2 01-08-2008 02:45 PM
IPC msgrcv - writing overflows memory extra 4 bytes tara Programming 1 11-08-2005 11:40 PM
examine memory with gdb Ephracis Programming 2 05-31-2005 06:30 AM
Can you use GDB to alter memory? tim_l Linux - Software 0 02-25-2005 05:19 AM
Scanning for AP's in range with acx110-card snablen Linux - Wireless Networking 2 12-20-2003 06:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration