Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Contabilización patatera de NOPs dentro de un ejecutable.
- * Copyright (C) 2012 Gonzalo J. Carracedo
- *
- * 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 3 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, see <http://www.gnu.org/licenses/>
- */
- #include <stdio.h>
- int
- main (int argc, char *argv[])
- {
- FILE *fp;
- unsigned char byte;
- int offset;
- int stripsize;
- int state;
- int total;
- if (argc != 2)
- {
- fprintf (stderr, "Usage: %s <executable file>\n", argv[0]);
- return 1;
- }
- if ((fp = fopen (argv[1], "rb")) == NULL)
- {
- perror (argv[1]);
- return 1;
- }
- state = 0;
- offset = 0;
- total = 0;
- while (fread (&byte, 1, 1, fp) == 1)
- {
- if (!state)
- {
- if (byte == 0x90) /* RET */
- {
- stripsize = 1;
- state++;
- }
- }
- else
- {
- if (byte == 0x90)
- stripsize++;
- else
- {
- if (stripsize > 4)
- {
- // fprintf (stderr, "%s: %d nops at 0x%08x\n", argv[1], stripsize, offset - stripsize);
- total += stripsize;
- }
- state--;
- }
- }
- offset++;
- }
- printf ("%s: %d nops available for fun and profit\n", argv[1], total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement