/* The IDA Pro Book - Listing 15-6 Copyright (C) 2008 Chris Eagle This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include static main() { auto addr, op, end, idx; auto func_flags, type, val, search; search = SEARCH_DOWN | SEARCH_NEXT; addr = GetFunctionAttr(ScreenEA(), FUNCATTR_START); func_flags = GetFunctionFlags(addr); if (func_flags & FUNC_FRAME) { //Is this an ebp based frame? end = GetFunctionAttr(addr, FUNCATTR_END); for (; addr < end && addr != BADADDR; addr = FindCode(addr, search)) { type = GetOpType(addr, 0); if (type == 3) { //Is this a register indirect operand? if (GetOperandValue(addr, 0) == 4) { //Is the register esp? MakeComm(addr, "arg_0"); //[esp] equates to arg_0 } } else if (type == 4) { //Is this a register + displacement operand? idx = strstr(GetOpnd(addr, 0), "[esp"); //Is the register esp? if (idx != -1) { val = GetOperandValue(addr, 0); //get the displacement MakeComm(addr, form("arg_%d", val)); //add a comment } } } } }