Skip to content

Commit

Permalink
Documenting/Licensing code
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandropellegrini committed Feb 24, 2015
1 parent 0cdf694 commit 773745b
Show file tree
Hide file tree
Showing 38 changed files with 966 additions and 214 deletions.
19 changes: 0 additions & 19 deletions AUTHORS

This file was deleted.

31 changes: 31 additions & 0 deletions AUTHORS.md
@@ -0,0 +1,31 @@

Authors and Contributors
========================

Hijacker could not have been possible without the help of many.


Current Maintainers
-------------------

* Alessandro Pellegrini <pellegrini@dis.uniroma1.it>
* Davide Cingolani <cingodvd@gmail.com>



Former Developers
-----------------

* Roberto Vitali <vitali@dis.uniroma1.it>



Patches, Fixes, and Contributions
---------------------------------

* Fernando Visca: Initial classification of x86 instructions, and
several bugfixes to the parser

* Alice Porfirio: Initial support for the XML rules, development
of several core internals, bugfixes to the x86 parser

38 changes: 29 additions & 9 deletions src/compile.h
@@ -1,14 +1,38 @@
/**
* Copyright (C) 2008-2015 HPDCS Group
* http://www.dis.uniroma1.it/~hpdcs
*
*
* This file is part of the Hijacker static binary instrumentation tool.
*
* Hijacker is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* Hijacker is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* hijacker; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @file compile.h
* @brief Compile and Link macros
* @author Alessandro Pellegrini
*/

#pragma once
#ifndef _COMPILE_H
#define _COMPILE_H


#include <prints.h>



// TODO: move to autotools
#ifndef COMPILER
/// What shhall we launch for compiling code?
/// What shall we launch for compiling code?
#define COMPILER "gcc"
#endif

Expand All @@ -17,12 +41,12 @@
#endif


// We must surround the compiler's name with quotes!
/// We must surround the compiler's name with quotes!
#define Q(x) #x
#define QUOTE(x) Q(x)


// Determine which support we have for launching a program
/// Determine which support we have for launching a program
#if defined(WIN32) || defined(WIN64)


Expand Down Expand Up @@ -116,8 +140,4 @@

#endif


//compile(prova)

#endif /* _COMPILE_H */

25 changes: 24 additions & 1 deletion src/executables/create.c
@@ -1,4 +1,27 @@

/**
* Copyright (C) 2008-2015 HPDCS Group
* http://www.dis.uniroma1.it/~hpdcs
*
*
* This file is part of the Hijacker static binary instrumentation tool.
*
* Hijacker is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* Hijacker is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* hijacker; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @file create.c
* @brief Multiplexer for the generation of output object files
* @author Alessandro Pellegrini
*/
#include <stdlib.h>

#include <hijacker.h>
Expand Down
26 changes: 25 additions & 1 deletion src/executables/elf/elf-defs.h
@@ -1,4 +1,28 @@
/* started on 22/09/2008 */
/**
* Copyright (C) 2008-2015 HPDCS Group
* http://www.dis.uniroma1.it/~hpdcs
*
*
* This file is part of the Hijacker static binary instrumentation tool.
*
* Hijacker is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* Hijacker is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* hijacker; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @file elf-defs.h
* @brief ELF-related abstraction definitions
* @author Alessandro Pellegrini
* @date September 22, 2008
*/

#ifndef _ELF_DEFS_H
#define _ELF_DEFS_H
Expand Down
126 changes: 25 additions & 101 deletions src/executables/elf/emit-elf.c
@@ -1,105 +1,29 @@
#if 0

#include <err.h>
#include <fcntl.h>
#include <libelf.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <unistd.h>

#define LOADADDR 0x08048000

unsigned char code[] = {
0xBB, 0x2A, 0x00, 0x00, 0x00, /* movl $42, %ebx */
0xB8, 0x01, 0x00, 0x00, 0x00, /* movl $1, %eax */
0xCD, 0x80 /* int $0x80 */
};

unsigned char strtab_ptr[] = {
0, '.', 't', 'e', 'x', 't', 0,
'.', 's', 'h', 's', 't', 'r', 't', 'a', 'b', 0
};

int main(int argc, char *argv[]) {
int fd;
Elf *e;
Elf_Scn *scn;
Elf_Data *data;
Elf64_Ehdr *ehdr;
Elf64_Phdr *phdr;
Elf64_Shdr *shdr;
if (argc != 2)
errx(EX_USAGE, "input... ./%s filename\n", argv[0]);
if (elf_version(EV_CURRENT) == EV_NONE)
errx(EX_SOFTWARE, "elf_version is ev_none, wtf? %s\n",
elf_errmsg(-1));
if ((fd = open(argv[1], O_WRONLY | O_CREAT, 0777)) < 0)
errx(EX_OSERR, "open %s\n", elf_errmsg(-1));
if ((e = elf_begin(fd, ELF_C_WRITE, NULL)) == NULL)
errx(EX_SOFTWARE, "elf_begin %s\n", elf_errmsg(-1));
if ((ehdr = elf64_newehdr(e)) == NULL)
errx(EX_SOFTWARE, "elf64_newehdr %s\n", elf_errmsg(-1));
/*
without these definitions objdump/readelf/strace/elf loader
will fail to load the binary correctly
be sure to pick them carefully and correctly, preferred exactly like the
ones like the system you are running on (so if you are running x86,
pick the same values you seen on a regular readelf -a /bin/ls
*/
size_t ehdrsz, phdrsz;

ehdrsz = elf64_fsize(ELF_T_EHDR, 1, EV_CURRENT);
phdrsz = elf64_fsize(ELF_T_PHDR, 1, EV_CURRENT);

ehdr->e_ident[EI_DATA] = ELFDATA2LSB;
ehdr->e_ident[EI_CLASS] = ELFCLASS64;
ehdr->e_machine = EM_386;
ehdr->e_type = ET_EXEC;
ehdr->e_entry = LOADADDR + ehdrsz + phdrsz;

if ((phdr = elf64_newphdr(e, 1)) == NULL)
errx(EX_SOFTWARE, "elf64_newphdr %s\n", elf_errmsg(-1));
if ((scn = elf_newscn(e)) == NULL)
errx(EX_SOFTWARE, "elf64_newscn %s\n", elf_errmsg(-1));

if ((data = elf_newdata(scn)) == NULL)
errx(EX_SOFTWARE, "elf64_newdata %s\n", elf_errmsg(-1));

data->d_align = 1;
data->d_off = 0LL;
data->d_buf = code;
data->d_type = ELF_T_BYTE;
data->d_size = sizeof(code);
data->d_version = EV_CURRENT;
if ((shdr = elf64_getshdr(scn)) == NULL)
errx(EX_SOFTWARE,"elf64_getshdr %s\n", elf_errmsg(-1));

shdr->sh_name = 1; /* Offset of ".text", see below. */
shdr->sh_type = SHT_PROGBITS;
shdr->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
shdr->sh_addr = LOADADDR + ehdrsz + phdrsz;
if ((phdr = elf64_newphdr(e,1)) == NULL)
errx(EX_SOFTWARE,"elf64_newphdr %s\n", elf_errmsg(-1));

phdr->p_type = PT_LOAD;
phdr->p_offset = 0;
phdr->p_filesz = ehdrsz + phdrsz + sizeof(code);
phdr->p_memsz = phdr->p_filesz;
phdr->p_vaddr = LOADADDR;
phdr->p_paddr = phdr->p_vaddr;
phdr->p_align = 4;
phdr->p_flags = PF_X | PF_R;
elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY);
if (elf_update(e, ELF_C_WRITE) < 0)
errx(EX_SOFTWARE, "elf64_update_2 %s\n", elf_errmsg(-1));

elf_end(e);
close(fd);
return 1;
}
/**
* Copyright (C) 2008-2015 HPDCS Group
* http://www.dis.uniroma1.it/~hpdcs
*
*
* This file is part of the Hijacker static binary instrumentation tool.
*
* Hijacker is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* Hijacker is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* hijacker; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @file emit-elf.c
* @brief Code to generate an ELF file from the Intermediate Representation
* @author Davide Cingolani
* @date May 20, 2014
*/

#endif /* 0 */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Expand Down
34 changes: 27 additions & 7 deletions src/executables/elf/emit-elf.h
@@ -1,10 +1,30 @@
/*
* emit-elf.h
*
* Created on: 20/mag/2014
* Author: davide
*/

/**
* Copyright (C) 2008-2015 HPDCS Group
* http://www.dis.uniroma1.it/~hpdcs
*
*
* This file is part of the Hijacker static binary instrumentation tool.
*
* Hijacker is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* Hijacker is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* hijacker; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @file emit-elf.c
* @brief Code to generate an ELF file from the Intermediate Representation
* @author Davide Cingolani
* @date May 20, 2014
*/

#pragma once
#ifndef EMIT_ELF_H_
#define EMIT_ELF_H_

Expand Down
27 changes: 23 additions & 4 deletions src/executables/elf/handle-elf.c
@@ -1,14 +1,33 @@

/**
* This file provides functions to manipulate parsed ELF structure.
*/
* Copyright (C) 2008-2015 HPDCS Group
* http://www.dis.uniroma1.it/~hpdcs
*
*
* This file is part of the Hijacker static binary instrumentation tool.
*
* Hijacker is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* Hijacker is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* hijacker; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @file handle-elf.c
* @brief Functions to manipulate already-parsed ELF object files
* @author Davide Cingolani
*/

#include <stdio.h>
#include <string.h>

#include <hijacker.h>
#include <prints.h>

#include <executable.h>
#include <instruction.h>

Expand Down

0 comments on commit 773745b

Please sign in to comment.