exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

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.

SHA-256 | 04004d4e5e5743978d087451e5eb2c0f3d8e7662be4e402f57cebb2c01305e4d

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);
}

Login or Register to add favorites

File Archive:

December 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close