Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Auto rename Tatanga/Gataka names
- //
- #include <idc.idc>
- static main() {
- auto FunctionStart, FunctionEnd, curr, FunctionName;
- auto s, fc;
- for (FunctionStart=NextFunction(0); FunctionStart != BADADDR; FunctionStart=NextFunction(FunctionStart) )
- {
- FunctionEnd = GetFunctionAttr(FunctionStart, FUNCATTR_END);
- for(curr = FunctionStart; curr <= FunctionEnd; curr = curr + ItemSize(curr))
- {
- // Filter pushes
- if(GetMnem(curr) != "push" || ItemSize(curr) != 5)
- continue;
- // Only ASCII strings
- if(GetStringType(GetOperandValue(curr, 0)) != 0)
- continue;
- s = GetString(GetOperandValue(curr, 0), -1, 0);
- // Filter filename (check for drive)
- if(substr(s, 1, 2) == ":")
- continue;
- fc = substr(s, 0, 1);
- // Filter to valid first char for function name
- if(!(fc >= "a" && fc <= "z") && !(fc >= "A" && fc <= "Z"))
- continue;
- FunctionName = GetFunctionNameXXXX(s);
- if(FunctionName == "")
- continue;
- if(AskYN(0, FunctionName) == 1)
- {
- RenameFunc(FunctionStart, FunctionName);
- break;
- }
- }
- }
- }
- static GetFunctionNameXXXX(unprocessed_name)
- {
- auto name, i, curr;
- auto ValidName;
- i = 0;
- while(i < strlen(unprocessed_name))
- {
- curr = substr(unprocessed_name, i, i+1);
- // Invalid char in func name
- if(!(curr >= "a" && curr <= "z") && !(curr >= "A" && curr <= "Z") && !(curr >= "0" && curr <= "9") && curr != ":")
- {
- return "";
- }
- // end of name
- if(curr == ":" && substr(unprocessed_name, i+1, i+2) == " ")
- {
- return name;
- }
- // append
- i++;
- name = substr(unprocessed_name, 0, i);
- // skip second ":" of class
- if(curr == ":" && substr(unprocessed_name, i, i+1) == ":")
- i++;
- }
- return "";
- }
- // 1 = Success, 0 = Failure
- static RenameFunc( dwAddress, sFunction )
- {
- auto dwRet;
- dwRet = MakeNameEx( dwAddress, sFunction, SN_NOCHECK );
- if( dwRet == 0 )
- {
- auto sTemp, i;
- for( i = 0; i < 32; i++ )
- {
- sTemp = form( "%s_%i", sFunction, i );
- if( ( dwRet = MakeNameEx( dwAddress, sTemp, SN_NOCHECK ) ) != 0 )
- {
- Message( "Info: Renamed to %s instead of %s\n", sTemp, sFunction );
- break;
- }
- }
- }
- return dwRet;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement