what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

cdump.c

cdump.c
Posted Jul 17, 2002
Authored by netric, PoWeR PoRK | Site netric.org

Simple pipe driven utility for creating c-style char decs from binary input. Can be of use for embedding shellcode etc in c sourcefiles.

tags | shellcode
systems | unix
SHA-256 | 4a6f029c31af9c526bea153a129ac74524a75df0ffb07a45e880902c7f0e3df0

cdump.c

Change Mirror Download
/*
* [cdump 0.1 by PoWeR_PoRK of netric (http://www.netric.org)]
*
* Simple pipe driven utility for creating c-style char decs from binary
* input. Can be of use for embedding shellcode etc in c sourcefiles.
* Do "./shdump -h" for a usage overview.
*/

#include <stdio.h>

char usage[] =
"Usage: ./cdump [-h][-n <var name>][-u][-s <linesize>][-c [-cu]]\n"
"Pipe driven utility for coverting binary data to c char declaration.\n"
"Example: cat binfile | ./shdump -u -s 20 >> bin.c\n"
"This adds the contents of binfile to bin.c in char declaration format\n\n"

"-h <var name> See this usage overview\n"
"-n Name of the char identifier (maxsize=30, default=foobar)\n"
"-u Set this to uppercase the hex output\n"
"-s <linesize> Set the maximum line size per byte input (default=10)\n"
"-c Comment the byte offsets into the output\n"
"-cu Set this to uppercase hex chars in byte offset comment\n";

int main(int argc, char **argv[])
{
int i = -2,oldi, lsize = 10, ucase = 0, npar = 1, cc = 1, cmt = 0, cucase = 0;
unsigned long place = 0;
char c, vname[31];
vname[30] = 0;
strncpy(&vname, "foobar", 30);

if(argc > 1){
if(!strncmp(argv[1], "-h", 2)){
printf("%s", &usage);
exit(0);
}

while(npar <= 5 && npar <= (argc - 1)){
if(!strncmp(argv[npar], "-n", 2)){
strncpy(&vname, argv[npar+1], 30);
npar+=2;
}else if(!strncmp(argv[npar], "-u", 2)){
ucase = 1;
npar++;
}else if(!strncmp(argv[npar], "-s", 2)){
lsize = atoi(argv[npar+1]);
npar+=2;
}else if(!strncmp(argv[npar], "-c", 2)){
cmt = 1;
npar++;
if(npar <= (argc - 1)){
if(!strncmp(argv[npar], "-cu", 3)){
cucase = 1;
npar++;
}
}
}else{
npar = argc;
}
}

}

if(strchr((char *)&vname, 37) != NULL){
printf("Cheeky Bastard! :P (fmt exploitation not allowed)\n");
exit(0);
}

oldi = getchar();
printf("char %s =\n/* 0000:0000 */ \"", (char *)&vname);
while(oldi != EOF )
{
if( ucase == 0 ){
printf("\\x%.2x", oldi);
}else if( ucase == 1 ){
printf("\\x%.2X", oldi);
}
if(cc >= lsize){
if(cmt == 1){
place += cc;
if(cucase == 1){
printf("\"\n/* %.4X:%.4X */ ", *((unsigned short *)&place + 1), *((unsigned short *)&place));
}else{
printf("\"\n/* %.4x:%.4x */ ", *((unsigned short *)&place + 1), *((unsigned short *)&place));
}
}else{
printf("\"\n");
}
printf("\"");
cc = 0;
}
cc++;
oldi = getchar();
}
printf("\";\n");
return 0;
}
Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    8 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    11 Files
  • 23
    Apr 23rd
    68 Files
  • 24
    Apr 24th
    23 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close