Permalink
Browse files

Fixing the library to make it -Wall -pedantic compilant

  • Loading branch information...
1 parent 0ba4787 commit a1117d6e343d1a43de999d0d218a227e23e63a4a BlackLight committed Jun 29, 2009
Showing with 43 additions and 37 deletions.
  1. +4 −4 LICENCE
  2. +11 −10 Makefile
  3. +5 −4 include/elfshark.h
  4. +1 −1 src/decode.c
  5. +1 −7 src/elf.c
  6. +2 −2 src/op_bits8.c
  7. +7 −3 src/op_jmp.c
  8. +0 −1 src/op_pushpop.c
  9. +7 −3 src/op_reg32.c
  10. +5 −2 src/utils.c
View
@@ -1,21 +1,21 @@
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.
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
Software Foundation; either version 3 or (at your option) any later
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
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 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.
As a special exception, if other files instantiate templates or use
View
@@ -2,18 +2,19 @@ SRCDIR=src
INCLUDEDIR=include
PREFIX=/usr/local
LIB=elfshark
+OPTS=-Wall -pedantic
all:
- gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/decode.c
- gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/elf.c
- gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_bits8.c
- gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_jmp.c
- gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_pushpop.c
- gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_reg32.c
- gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_scal32.c
- gcc -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_scal81.c
- gcc -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)/decode.c
+ gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/elf.c
+ gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_bits8.c
+ gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_jmp.c
+ gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_pushpop.c
+ gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_reg32.c
+ gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_scal32.c
+ gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/op_scal81.c
+ gcc $(OPTS) -I$(INCLUDEDIR) -fPIC -g -c $(SRCDIR)/single.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
ar rcs lib$(LIB).a *.o
View
@@ -5,18 +5,18 @@
*
* 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
* Software Foundation; either version 3 or (at your option) any later
* 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
* 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 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.
*
* As a special exception, if other files instantiate templates or use
@@ -72,7 +72,7 @@
typedef unsigned char u8;
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);
char* decode_to_asm (u8 code[], u32 len, u32 init_addr, u8 opts);
@@ -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_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_rotsh (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts);
#endif
View
@@ -7,7 +7,7 @@
#define LINESIZE 0xff
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 line[LINESIZE];
View
@@ -9,14 +9,8 @@
unsigned char* get_executable_elf_code(char *fname, int *code_size, int *addr) {
unsigned char *code;
- int i,j,fd;
- int hlen,s_off;
-
- u8 buff8;
- u16 buff16;
- u32 buff32;
+ int fd, hlen, s_off;
Elf32_Ehdr elfhdr;
- Elf32_Shdr s_hdr;
if (!fname)
return NULL;
View
@@ -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);
break;
}
+
+ return 0;
}
int op_reg8 (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
- int i;
char srcreg[8], dstreg[8];
- u32 offset;
if (len < 2) return -1;
View
@@ -26,6 +26,8 @@ int op_jmp (char* op, u8 code[], u8 len, char buf[], u8 buflen, u32 addr, u8 opt
else
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) {
@@ -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)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t[%s]\n", op, dstreg);
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;
case 0x01:
@@ -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)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t[%s+%d]\n", op, dstreg, code[2]);
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;
case 0x03:
if ((opts & 0x1) == INTEL_FLAVOR)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s\n", op, dstreg);
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;
}
+
+ return 0;
}
View
@@ -3,7 +3,6 @@
#include "elfshark.h"
int op_pushpop (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
- int i;
char dstreg[8];
u32 var;
View
@@ -3,7 +3,6 @@
#include "elfshark.h"
int op_reg32 (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
- int i;
char srcreg[8], dstreg[8];
u32 offset;
@@ -32,7 +31,7 @@ int op_reg32 (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
if ((opts & 0x1) == INTEL_FLAVOR)
snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\tDWORD PTR 0x%x,eax\n", op, offset);
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;
}
@@ -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);
break;
}
+
+ return 0;
}
int op_reg32_inv (char* op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
- int i;
char srcreg[8], dstreg[8];
u32 offset;
@@ -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);
break;
}
+
+ return 0;
}
void op_incdec (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
@@ -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",
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) {
View
@@ -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]);
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) {
@@ -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",
code[off_index], (opts & BITS_16) ? "ax" : "eax");
else
- snprintf (buf, buflen, "out\t%%eax,$0x%x\n",
- code[off_index], (opts & BITS_16) ? "%%ax" : "%%eax");
+ snprintf (buf, buflen, "out\t%s,$0x%x\n",
+ (opts & BITS_16) ? "%%ax" : "%%eax", code[off_index]);
break;
case 0xec:
@@ -353,6 +354,8 @@ int op_inout (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {
(opts & BITS_16) ? "%%ax" : "%%eax");
break;
}
+
+ return 0;
}
void unknown (u8 code[], u8 len, char buf[], u8 buflen, u8 opts) {

0 comments on commit a1117d6

Please sign in to comment.