evolve or die

core-locate.c

core-locate.c
Posted Apr 16, 2003
Authored by electronicsouls

This utility will search in a binary or core dump for a user supplied string and return the exact location in memory.

MD5 | e53634887d4d77071a0dcd24a848922d

core-locate.c

Change Mirror Download
/*
* 0x4553 - ElectronicSouls - 0x4553
* search in a binary or core dump for a user supplied string and get the exact location in memory.
* idea is based on sectorx's segment.c which is much better, but this was made for fun and works well so wtf :)
*/

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <elf.h>


void Header(int fd)
{
Elf32_Ehdr ehdr;
lseek(fd,0,SEEK_SET);

read(fd,&ehdr,sizeof(Elf32_Ehdr));

fprintf(stderr,"ELF Binary Header:\n");
fprintf(stderr,"ident..: %s\n",ehdr.e_ident);
fprintf(stderr,"type...: ");

switch (ehdr.e_type){
case 2:
printf("Executable\n");
break;
case 4:
printf("Core\n");
break;
default:
printf("Invalid File!\n");
exit(1);
break;
}
fprintf(stderr,"\n");
}

int main(int argc, char *argv[])
{
struct stat st_str;

Elf32_Ehdr *elf_hdr;
Elf32_Phdr *p_hdr;

char *file_buf;

int fd = 0,
i = 0,
e = 0,
s;

fprintf(stderr,"\n[MemLocate]\n");

if(argc<3) {
fprintf(stderr, "%s [core] [string]\n", argv[0]);
return(-1);
}

if((fd=open(argv[1],O_RDONLY))<0) {
fprintf(stderr, "Unable to open file!\n");
return(-1);
}

fprintf(stderr,"%s has a valid format!\n",argv[1]);
fprintf(stderr,"trying to locate string: %s\n\n",argv[2]);

fstat(fd,&st_str);

file_buf=(char *)malloc(st_str.st_size);
memset(file_buf,0,st_str.st_size);

if (read(fd,file_buf,st_str.st_size)<0) {
fprintf(stderr, "error! read() failed..\n");
free(file_buf);
close(fd);

return(-1);
}

elf_hdr = (Elf32_Ehdr *)file_buf;
Header(fd);

for (i=0; i < elf_hdr->e_phnum; i++)
{
p_hdr = (Elf32_Phdr *)
(file_buf+elf_hdr->e_phoff+(i*elf_hdr->e_phentsize));

for (e = p_hdr->p_offset;
e < p_hdr->p_offset+p_hdr->p_filesz;
e++)

if(!strncmp(file_buf+e,argv[2],strlen(argv[2]))){

fprintf(stderr, "[String found at: 0x%08x]\n",
((p_hdr->p_vaddr+e) - p_hdr->p_offset));
}
}

fprintf(stderr,"\n");

free(file_buf);

close(fd);

exit(0);
}

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

May 2012

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    37 Files
  • 2
    May 2nd
    53 Files
  • 3
    May 3rd
    33 Files
  • 4
    May 4th
    4 Files
  • 5
    May 5th
    10 Files
  • 6
    May 6th
    17 Files
  • 7
    May 7th
    19 Files
  • 8
    May 8th
    36 Files
  • 9
    May 9th
    34 Files
  • 10
    May 10th
    35 Files
  • 11
    May 11th
    20 Files
  • 12
    May 12th
    18 Files
  • 13
    May 13th
    11 Files
  • 14
    May 14th
    27 Files
  • 15
    May 15th
    58 Files
  • 16
    May 16th
    54 Files
  • 17
    May 17th
    25 Files
  • 18
    May 18th
    53 Files
  • 19
    May 19th
    9 Files
  • 20
    May 20th
    15 Files
  • 21
    May 21st
    25 Files
  • 22
    May 22nd
    32 Files
  • 23
    May 23rd
    35 Files
  • 24
    May 24th
    26 Files
  • 25
    May 25th
    25 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2012 Packet Storm. All rights reserved.

close