what you don't know can hurt you
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:

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