So since I've been having issues w/searchign for floats I thought I would create an IDA script to do just that. Simply run the script, it will ask you for an exact float, and it will search for it.
One issue I'm running into, I'd like for it to be able to search for ranges w/in the vicinity of the number you are searching for. So for example, lets say you are searching for:
0.01666666666666667
Well I'd like to automatically "move down" the float until I hit the first non-0 value (which would be 1). Then I'd like to increment + decrement by 1 and search for that range. So the search would be for values in between:
0.00666666666666667 and 0.02666666666666667
Sad question I know, and I feel like the solution is simple, but I'm stumped. Anyone have any recommendations on how to go about it (bit shifting/comparison of some type?)
Thanks!
Code:
#include <idc.idc>
static _Search(segStart, segEnd, size, searchValue){
auto address, flags, result, value;
Message("\nSearching for %f", searchValue);
address = segStart;
while ( address < segEnd ){
flags = GetFlags(address);
// we have valid data here
if ( isData(flags) ){
// if we want to do some searching!
if ( size == 0x4 ){
value = GetFloat(address);
}
else if ( size == 0x8 ){
value = GetDouble(address);
}
//19.291105
if ( value == searchValue ){
Message("\n Value at 0x%X is %f", address, value);
}
}
// increase by size!
address = address + size;
}
}
static main(){
auto segPointer, segStart, segEnd, segName, searchValue;
searchValue = AskStr( "0.0" , "Please enter a float/double value to search for");
// Get the pointer to our first segment
segPointer = FirstSeg();
while (segPointer != BADADDR){
segName = SegName(segPointer);
segStart = SegStart(segPointer);
segEnd = SegEnd(segPointer);
// floats
if ( segName == "__literal4" ){
_Search(segStart, segEnd, 0x4, searchValue);
}
// doubles
else if ( segName == "__literal8" ){
_Search(segStart, segEnd, 0x8, searchValue);
}
segPointer = NextSeg( segPointer );
}
}