Small application written to make life easier. It dumps C style opcodes between two provided offsets.
4e7b34bd72aa38097381c48faee3882bfff8bfafa9e16fcbd8a7d692399b7651
/*
* ~[ fm-dmpsc.c ]
*
* Dump the opcodes from a file, starting from an offset provided.
*
* written by -( nemo @ felinemenace.org )-
*
* _,'| _.-''``-...___..--';)
* /_ \'. __..-' , ,--...--'''
* <\ .`--''' ` /'
* `-';' ; ; ;
* __...--'' ___...--_..' .;.'
* fL (,__....----''' (,..--''
* -( http://www.felinemenace.org )-
*
*/
#include <stdio.h>
#include <errno.h>
#define MAXSC 10000
void usage(char *file)
{
printf("usage: %s <file> <offset1> [<offset2>]\n",file);
exit(1);
}
int main(int ac, char **av)
{
char shellcode[MAXSC] = "char shellcode[] = {\n\"";
unsigned int curr,offset1,offset2 = 0xffffffff;
FILE *fp;
char *ptr = shellcode + strlen(shellcode) - 1;
unsigned char hex;
int cnt = 0;
if(ac < 3 || ac > 4)
usage(*av);
sscanf(av[2],"%p",&offset1);
if(av[3])
sscanf(av[3],"%p",&offset2);
if(offset2 <= offset1)
usage(*av);
if(!(fp = fopen(av[1],"r+"))) {
printf("Error opening file.\n");
exit(1);
}
if(fseek(fp,offset1,SEEK_SET) == -1){
printf("Error seeking to offset1.\n");
exit(1);
}
do {
if((offset1 + cnt) >= offset2) {
break;
}
if(cnt && !(cnt % 16)) {
strcat(ptr,"\"\n\"");
ptr+=3;
}
strcat(ptr,"\\x");
if(!(fread(&hex, 1,1,fp) ==1)) {
if(errno) {
printf("An error has occured reading from the file.\n");
exit(1);
}
break;
}
ptr+=3;
sprintf(ptr,"%02x",hex);
cnt++;
} while(ptr++ < (shellcode + MAXSC - 4)) ;
strcat(ptr,"\"\n};\n");
printf("// shellcode generated by -( nemo@felinemenace.org )-\n");
printf("%s\n",shellcode);
return 0;
}