发新话题
打印

[转载]dumps C style opcodes between two provided offsets

[转载]dumps C style opcodes between two provided offsets

文章作者:nemo@felinemenace.org
复制内容到剪贴板
代码:
/*
* ~[ fm-dmpsc.c ]  
*
* Dump the opcodes from a file, starting from an offset provided.
*
* written by -( nemo @ felinemenace.org )-
*
*              _,'|         _.-''``-...___..--';)
*              /_ \'.    __..-' ,    ,--...--'''
*             <\   .`--&#39;&#39;&#39;     `    /&#39;
*             `-&#39;;&#39;          ;  ; ;
*          __...--&#39;&#39;    ___...--_..&#39;  .;.&#39;
*       fL (,__....----&#39;&#39;&#39;     (,..--&#39;&#39;  
*         -( [url]http://www.felinemenace.org[/url] )-
*
*/

#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 -( [email]nemo@felinemenace.org[/email] )-\n");
    printf("%s\n",shellcode);

    return 0;
}
qq310926是我唯一用号,除此之外有其他号码号自称邪八冰血封情,则非本人。

TOP

发新话题