Skip to content

Commit

Permalink
Fixing the library to make it -Wall -pedantic compilant
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackLight committed Jun 29, 2009
1 parent 0ba4787 commit a1117d6
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 37 deletions.
8 changes: 4 additions & 4 deletions LICENCE
Original file line number Original file line Diff line number Diff line change
@@ -1,21 +1,21 @@
The files in this directory and elsewhere which refer to this LICENCE The files in this directory and elsewhere which refer to this LICENCE
file are part of uSock, the library for the high-level management of file are part of ElfShark, the library for the high-level management of
network sockets. network sockets.


Copyright ? 2009 BlackLight Copyright ? 2009 BlackLight


uSock is free software; you can redistribute it and/or modify it under ElfShark 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 the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 or (at your option) any later Software Foundation; either version 3 or (at your option) any later
version. version.


uSock is distributed in the hope that it will be useful, but WITHOUT ElfShark is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details. for more details.


You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with uSock; if not, write to the Free Software Foundation, Inc., with ElfShark; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.


As a special exception, if other files instantiate templates or use As a special exception, if other files instantiate templates or use
Expand Down
21 changes: 11 additions & 10 deletions Makefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ SRCDIR=src
INCLUDEDIR=include INCLUDEDIR=include
PREFIX=/usr/local PREFIX=/usr/local
LIB=elfshark LIB=elfshark
OPTS=-Wall -pedantic


all: all:
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/decode.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/decode.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/elf.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/elf.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_bits8.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_bits8.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_jmp.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_jmp.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_pushpop.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_pushpop.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_reg32.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_reg32.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_scal32.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_scal32.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_scal81.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_scal81.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/single.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/single.c
gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/utils.c gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/utils.c
gcc -shared -Wl,-soname,lib$(LIB).so.0 -o lib$(LIB).so.0.0.0 *.o gcc -shared -Wl,-soname,lib$(LIB).so.0 -o lib$(LIB).so.0.0.0 *.o
ar rcs lib$(LIB).a *.o ar rcs lib$(LIB).a *.o


Expand Down
9 changes: 5 additions & 4 deletions include/elfshark.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* *
* Copyright (C) 2009 BlackLight * Copyright (C) 2009 BlackLight
* *
* uSock is free software; you can redistribute it and/or modify it under * ElfShark 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 * the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 or (at your option) any later * Software Foundation; either version 3 or (at your option) any later
* version. * version.
* *
* uSock is distributed in the hope that it will be useful, but WITHOUT * ElfShark is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with uSock; if not, write to the Free Software Foundation, Inc., * with ElfShark; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* *
* As a special exception, if other files instantiate templates or use * As a special exception, if other files instantiate templates or use
Expand Down Expand Up @@ -72,7 +72,7 @@


typedef unsigned char u8; typedef unsigned char u8;
typedef unsigned short int u16; typedef unsigned short int u16;
typedef unsigned long int u32; typedef unsigned int u32;


unsigned char* get_executable_elf_code(char *fname, int *code_size, int *addr); unsigned char* get_executable_elf_code(char *fname, int *code_size, int *addr);
char* decode_to_asm (u8 code[], u32 len, u32 init_addr, u8 opts); char* decode_to_asm (u8 code[], u32 len, u32 init_addr, u8 opts);
Expand Down Expand Up @@ -104,6 +104,7 @@ int op_lea32 (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts);
int op_inout (u8 code[], u8 len, char buf[], u8 buflen, u8 opts); int op_inout (u8 code[], u8 len, char buf[], u8 buflen, u8 opts);
int op_notneg (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts); int op_notneg (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts);
int op_muldiv (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts); int op_muldiv (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts);
int op_rotsh (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts);


#endif #endif


2 changes: 1 addition & 1 deletion src/decode.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define LINESIZE 0xff #define LINESIZE 0xff


char* decode_to_asm (u8 code[], u32 len, u32 init_addr, u8 opts) { char* decode_to_asm (u8 code[], u32 len, u32 init_addr, u8 opts) {
u32 i, j, increment = 0, buflen = 0; u32 i, increment = 0, buflen = 0;
char* buf = NULL; char* buf = NULL;
char line[LINESIZE]; char line[LINESIZE];


Expand Down
8 changes: 1 addition & 7 deletions src/elf.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@


unsigned char* get_executable_elf_code(char *fname, int *code_size, int *addr) { unsigned char* get_executable_elf_code(char *fname, int *code_size, int *addr) {
unsigned char *code; unsigned char *code;
int i,j,fd; int fd, hlen, s_off;
int hlen,s_off;

u8 buff8;
u16 buff16;
u32 buff32;
Elf32_Ehdr elfhdr; Elf32_Ehdr elfhdr;
Elf32_Shdr s_hdr;


if (!fname) if (!fname)
return NULL; return NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/op_bits8.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ int op_scal8 (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t$0x%x,%s\n", op, code[1], reg); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t$0x%x,%s\n", op, code[1], reg);
break; break;
} }

return 0;
} }


int op_reg8 (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { int op_reg8 (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
int i;
char srcreg[8], dstreg[8]; char srcreg[8], dstreg[8];
u32 offset;


if (len < 2) return -1; if (len < 2) return -1;


Expand Down
10 changes: 7 additions & 3 deletions src/op_jmp.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ int op_jmp (char* op, u8 code[], u8 len, char buf[], u8 buflen, u32 addr, u8 opt
else else
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t0x%x\n", op, (addr + neg_off)); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t0x%x\n", op, (addr + neg_off));
} }

return 0;
} }


int op_jmp_ff (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { int op_jmp_ff (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
Expand All @@ -40,7 +42,7 @@ int op_jmp_ff (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
if ((opts & 0x1) == INTEL_FLAVOR) if ((opts & 0x1) == INTEL_FLAVOR)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t[%s]\n", op, dstreg); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t[%s]\n", op, dstreg);
else else
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s,*(%s)\n", op, dstreg); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t*(%s)\n", op, dstreg);
break; break;


case 0x01: case 0x01:
Expand All @@ -49,15 +51,17 @@ int op_jmp_ff (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
if ((opts & 0x1) == INTEL_FLAVOR) if ((opts & 0x1) == INTEL_FLAVOR)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t[%s+%d]\n", op, dstreg, code[2]); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t[%s+%d]\n", op, dstreg, code[2]);
else else
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s,*0x%x(%s)\n", op, code[2], dstreg); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t*0x%x(%s)\n", op, code[2], dstreg);
break; break;


case 0x03: case 0x03:
if ((opts & 0x1) == INTEL_FLAVOR) if ((opts & 0x1) == INTEL_FLAVOR)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s\n", op, dstreg); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s\n", op, dstreg);
else else
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s,*%s\n", op, dstreg); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t*%s\n", op, dstreg);
break; break;
} }

return 0;
} }


1 change: 0 additions & 1 deletion src/op_pushpop.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "elfshark.h" #include "elfshark.h"


int op_pushpop (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { int op_pushpop (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
int i;
char dstreg[8]; char dstreg[8];
u32 var; u32 var;


Expand Down
10 changes: 7 additions & 3 deletions src/op_reg32.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "elfshark.h" #include "elfshark.h"


int op_reg32 (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { int op_reg32 (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
int i;
char srcreg[8], dstreg[8]; char srcreg[8], dstreg[8];
u32 offset; u32 offset;


Expand Down Expand Up @@ -32,7 +31,7 @@ int op_reg32 (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
if ((opts & 0x1) == INTEL_FLAVOR) if ((opts & 0x1) == INTEL_FLAVOR)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\tDWORD PTR 0x%x,eax\n", op, offset); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\tDWORD PTR 0x%x,eax\n", op, offset);
else else
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s,0x%%eax\n", op, offset); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t$0x%x,%%eax\n", op, offset);


return 0; return 0;
} }
Expand Down Expand Up @@ -113,10 +112,11 @@ int op_reg32 (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s,%s\n", op, srcreg, dstreg); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s,%s\n", op, srcreg, dstreg);
break; break;
} }

return 0;
} }


int op_reg32_inv (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { int op_reg32_inv (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
int i;
char srcreg[8], dstreg[8]; char srcreg[8], dstreg[8];
u32 offset; u32 offset;


Expand Down Expand Up @@ -188,6 +188,8 @@ int op_reg32_inv (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t0x%x(%s),%s\n", op, offset, srcreg, dstreg); snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t0x%x(%s),%s\n", op, offset, srcreg, dstreg);
break; break;
} }

return 0;
} }


void op_incdec (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { void op_incdec (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
Expand Down Expand Up @@ -234,6 +236,8 @@ int op_lea32 (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t0x%x(%s),%s\n", snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t0x%x(%s),%s\n",
op, ((code[1] & 0x07) == 0x04) ? code[3] : code[2], srcreg, dstreg); op, ((code[1] & 0x07) == 0x04) ? code[3] : code[2], srcreg, dstreg);
} }

return 0;
} }


int op_notneg (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { int op_notneg (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
Expand Down
7 changes: 5 additions & 2 deletions src/utils.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ int interrupt (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {


if ((opts & 0x1) == INTEL_FLAVOR) snprintf (buf, buflen, "int\t%xh\n", code[1]); if ((opts & 0x1) == INTEL_FLAVOR) snprintf (buf, buflen, "int\t%xh\n", code[1]);
else snprintf (buf, buflen, "int\t0x%x\n", code[1]); else snprintf (buf, buflen, "int\t0x%x\n", code[1]);
return 0;
} }


int op_inout (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { int op_inout (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
Expand Down Expand Up @@ -317,8 +318,8 @@ int op_inout (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
snprintf (buf, buflen, "out\t0x%x,%s\n", snprintf (buf, buflen, "out\t0x%x,%s\n",
code[off_index], (opts & BITS_16) ? "ax" : "eax"); code[off_index], (opts & BITS_16) ? "ax" : "eax");
else else
snprintf (buf, buflen, "out\t%%eax,$0x%x\n", snprintf (buf, buflen, "out\t%s,$0x%x\n",
code[off_index], (opts & BITS_16) ? "%%ax" : "%%eax"); (opts & BITS_16) ? "%%ax" : "%%eax", code[off_index]);
break; break;


case 0xec: case 0xec:
Expand Down Expand Up @@ -353,6 +354,8 @@ int op_inout (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
(opts & BITS_16) ? "%%ax" : "%%eax"); (opts & BITS_16) ? "%%ax" : "%%eax");
break; break;
} }

return 0;
} }


void unknown (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) { void unknown (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
Expand Down

0 comments on commit a1117d6

Please sign in to comment.