/* chartest.c * (C) Will Dyke, 2002 * * chartest goes through an objdump of a file, and outputs all lines * containing a compare of a constant (of the form $0x12ab) to something * e.g. register, memory address, whatever. * * 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 #include int main(int argc, char* argv[]) { char address[10], instruction[10], operands[30], *pch, s[30]; char linebuf[300]; int num; FILE *fptr= stdin; char *usage = "Usage: %s [filename]\n"; switch (argc) { case 1: fptr = stdin; break; case 2: if (!(fptr = fopen(argv[1], "r"))) { fprintf(stderr,"Couldn't open %s for reading\n", argv[1]); exit(1); } break; default: printf(usage, argv[0]); exit(2); } pch = linebuf; while (*pch = fgetc(fptr)) { int i= 0; if (*pch == EOF) { break; } if (*pch == '\n') { *pch = '\0'; pch = linebuf; } else { pch++; continue; } /* We're looking for lines with three fields only (address, instruction and operands), * where the instruction matches cmp.*, and where the first operand is a constant */ if (sscanf(linebuf, "%s %s %s %s", address, instruction, operands, s)==3 && !strncmp(instruction, "cmp", 3) && operands[0] == '$') { for (pch= operands+1; *pch!=','; pch++) { s[i++] = *pch; } s[i]='\0'; num = strtol(s, NULL, 16); /* We're only looking for compares with what * look like a typical ASCII printable character */ if (num >= 0x20 && num < 0x80) { printf("%s %s\t%c%s\n", address, instruction, num,pch); } } pch = linebuf; } }