diff --git a/build.sh b/build.sh index 00d62e817d717e391f38c6f5a35dee9d047a3b5d..457cd72eb527d45ab0363e348e1f544c443aa115 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,7 @@ -#!/bin/sh +#!/bin/bash + +export CC="cc -I/opt/csw/include -L /opt/csw/lib/" +export CXX="CC -I/opt/csw/include -L /opt/csw/lib/" #sanity check if [ $SECURITY_TRANSFORMS_HOME"X" = "X" ]; then diff --git a/include/i686/config.h b/include/i686/config.h index 2201420794ebea787a5ee6bf490f5888fcbe0e12..294979ee85d72df5b7c45c0dc72dd19157770cd0 100644 --- a/include/i686/config.h +++ b/include/i686/config.h @@ -58,17 +58,19 @@ typedef s_uint64_t counter_t; #define NULL 0 #endif +namespace std { #include <elf.h> - -typedef Elf32_Ehdr IRDB_Elf_Ehdr; -typedef Elf32_Shdr IRDB_Elf_Shdr; -typedef Elf32_Off IRDB_Elf_Off; -typedef Elf32_Half IRDB_Elf_Half; -typedef Elf32_Word IRDB_Elf_Word; -typedef Elf32_Addr IRDB_Elf_Addr; -typedef Elf32_Sym IRDB_Elf_Sym; -typedef Elf32_Rel IRDB_Elf_Rel; -typedef Elf32_Rela IRDB_Elf_Rela; +} + +typedef std::Elf32_Ehdr IRDB_Elf_Ehdr; +typedef std::Elf32_Shdr IRDB_Elf_Shdr; +typedef std::Elf32_Off IRDB_Elf_Off; +typedef std::Elf32_Half IRDB_Elf_Half; +typedef std::Elf32_Word IRDB_Elf_Word; +typedef std::Elf32_Addr IRDB_Elf_Addr; +typedef std::Elf32_Sym IRDB_Elf_Sym; +typedef std::Elf32_Rel IRDB_Elf_Rel; +typedef std::Elf32_Rela IRDB_Elf_Rela; #define IRDB_ELF_ST_TYPE ELF32_ST_TYPE diff --git a/libIRDB/Makefile b/libIRDB/Makefile index 88b2807c887449c23e6e0d30b4dafca6104eea7a..35d2b89b467f88ed27519b25d72a04fb6a483ea9 100644 --- a/libIRDB/Makefile +++ b/libIRDB/Makefile @@ -1,8 +1,12 @@ +CC="cc -I/opt/csw/include" +CXX="CC -I/opt/csw/include" + all: - cd src;make + cd src;make CC=$(CC) CXX=$(CXX) ./install_libs.sh - cd test;make + cd test;make CC=$(CC) CXX=$(CXX) + clean: cd src;make clean diff --git a/libIRDB/include/core/variantid.hpp b/libIRDB/include/core/variantid.hpp index 1117855b218451dbe0f9d479d4472d259af7ff46..fa75931e8a0cfe210551f294a2a5c71b43bf711d 100644 --- a/libIRDB/include/core/variantid.hpp +++ b/libIRDB/include/core/variantid.hpp @@ -1,6 +1,10 @@ #define CURRENT_SCHEMA 2 +class VariantID_t; + +std::ostream& operator<<(std::ostream& out, const libIRDB::VariantID_t& pid); + class VariantID_t : public BaseObj_t { public: @@ -52,4 +56,3 @@ class VariantID_t : public BaseObj_t }; -std::ostream& operator<<(std::ostream& out, const VariantID_t& pid); diff --git a/libIRDB/src/cfg/Makefile b/libIRDB/src/cfg/Makefile index 6058b7ec3e75ecd537b1fd9639ee5710282c4284..e411ee3477e07ca2cc0830f5a5729a880d6b55c1 100644 --- a/libIRDB/src/cfg/Makefile +++ b/libIRDB/src/cfg/Makefile @@ -11,5 +11,5 @@ clean: rm -f $(OBJS) .cpp.o: - g++ -g -c -I. -I../../include -I../../../beaengine/include $< + $(CXX) -g -c -I. -I../../include -I../../../beaengine/include $< ar rc $(LIB) $@ diff --git a/libIRDB/src/core/Makefile b/libIRDB/src/core/Makefile index f9a80e8d789aeba0bd116d18df4bd943a3b1f844..a8939e9240e6b4e68d7b0de4934a64b7359d66a1 100644 --- a/libIRDB/src/core/Makefile +++ b/libIRDB/src/core/Makefile @@ -12,5 +12,5 @@ clean: rm -f $(OBJS) .cpp.o: - g++ -g -c -I. -I../../include -I../../../beaengine/include $< + $(CXX) -g -c -I. -I../../include -I../../../beaengine/include $< ar rc $(LIB) $@ diff --git a/libIRDB/src/core/fileir.cpp b/libIRDB/src/core/fileir.cpp index bae0778d1758ad471162bfe1aad0108a88e49118..65a50cafd7f923bde72bacb73b5f5265aae4c848 100644 --- a/libIRDB/src/core/fileir.cpp +++ b/libIRDB/src/core/fileir.cpp @@ -5,6 +5,9 @@ #include <map> #include <fstream> #include <elf.h> +#include <stdlib.h> +#include <sys/wait.h> + using namespace libIRDB; using namespace std; @@ -506,8 +509,8 @@ void FileIR_t::WriteToDB() } string r=""; - std::set<Relocation_t*> relocs = (*i)->GetRelocations(); - for(set<Relocation_t*>::iterator it=relocs.begin(); it!=relocs.end(); ++it) + std::set<Relocation_t*> irelocs = (*i)->GetRelocations(); + for(set<Relocation_t*>::iterator it=irelocs.begin(); it!=irelocs.end(); ++it) { Relocation_t* reloc=*it; r+=reloc->WriteToDB(fileptr,*i); diff --git a/libIRDB/test/Makefile b/libIRDB/test/Makefile index 303e622b32930228b815ac53d7c7c9f9c3af5579..92d5ca2657d5e85a43dbd54574841b439fef9d93 100644 --- a/libIRDB/test/Makefile +++ b/libIRDB/test/Makefile @@ -7,7 +7,11 @@ OPT=-g PROGS=print_variant.exe list_programs.exe create_variant.exe create_variantir.exe read_variantir.exe clone.exe ilr.exe \ drop_variant.exe generate_spri.exe fill_in_cfg.exe fix_calls.exe fill_in_indtargs.exe unfix_calls.exe \ - calc_conflicts.exe find_strings.exe + find_strings.exe + + +# calc_conflicts.exe -- doesn't build on solaris and isn't necessary for anything. + all: $(PROGS) @@ -15,18 +19,18 @@ $(PROGS): ../../lib/* fill_in_indtargs.exe: read_ehframe.o fill_in_indtargs.o check_thunks.o - g++ fill_in_indtargs.o read_ehframe.o check_thunks.o $(INCLUDES) $(LIBS) $(OPT) -o $@ + $(CXX) fill_in_indtargs.o read_ehframe.o check_thunks.o $(INCLUDES) $(LIBS) $(OPT) -o $@ .o.exe: $< ../lib/libIRDB-core.a ../lib/libIRDB-cfg.a - g++ $< $(INCLUDES) $(LIBS) $(OPT) -o $@ + $(CXX) $< $(INCLUDES) $(LIBS) $(OPT) -o $@ .cpp.o: $< - g++ $< $(INCLUDES) $(LIBS) $(OPT) -o $@ -c + $(CXX) $< $(INCLUDES) $(LIBS) $(OPT) -o $@ -c # shouldn't be needed anymore #read_ehframe.o: read_ehframe.cpp -# g++ -w -fpermissive $(INCLUDES) $(LIBS) $(OPT) $^ -o $@ -c +# $(CXX) -w -fpermissive $(INCLUDES) $(LIBS) $(OPT) $^ -o $@ -c clean: rm -f $(PROGS) *.o diff --git a/libIRDB/test/calc_conflicts.cpp b/libIRDB/test/calc_conflicts.cpp index 0f597f34eedd0c9e2a964ddb28e8ac433b344a95..63dcf0a18e7acf4d9317b9209a605f52a3717e8a 100644 --- a/libIRDB/test/calc_conflicts.cpp +++ b/libIRDB/test/calc_conflicts.cpp @@ -10,6 +10,9 @@ #include <sys/mman.h> #include <ctype.h> #include "targ-config.h" +#include "elfio/elfio.hpp" +#include "elfio/elfio_dump.hpp" + #include "beaengine/BeaEngine.h" diff --git a/libIRDB/test/fill_in_cfg.cpp b/libIRDB/test/fill_in_cfg.cpp index 96ed9836094eb3592df5529c0ede069aa7d4476a..1c72f16746b59824eeb442e1167e7993a6f56e7e 100644 --- a/libIRDB/test/fill_in_cfg.cpp +++ b/libIRDB/test/fill_in_cfg.cpp @@ -9,10 +9,11 @@ #include <sys/mman.h> #include <ctype.h> +#include "targ-config.h" + #include "elfio/elfio.hpp" #include "elfio/elfio_dump.hpp" -#include "targ-config.h" #include "beaengine/BeaEngine.h" diff --git a/libIRDB/test/fill_in_indtargs.cpp b/libIRDB/test/fill_in_indtargs.cpp index 73878ceaeefc873e86e74f0bd1441d5445b96f74..45e12dfb892448050b02c0705ff7f15b4c6e75b1 100644 --- a/libIRDB/test/fill_in_indtargs.cpp +++ b/libIRDB/test/fill_in_indtargs.cpp @@ -10,9 +10,9 @@ // #include <elf.h> #include <ctype.h> +#include "targ-config.h" #include "elfio/elfio.hpp" #include "elfio/elfio_dump.hpp" -#include "targ-config.h" #include "beaengine/BeaEngine.h" #include "check_thunks.hpp" diff --git a/libIRDB/test/find_strings.cpp b/libIRDB/test/find_strings.cpp index 5b58de045408b493aaee393757314761cf319a8d..9c4dad39dde7525c85cfe127bce9574f0390eb4f 100644 --- a/libIRDB/test/find_strings.cpp +++ b/libIRDB/test/find_strings.cpp @@ -6,11 +6,13 @@ #include <stdlib.h> #include <cctype> #include <assert.h> +#include <stdlib.h> + +#include "targ-config.h" #include "elfio/elfio.hpp" #include "elfio/elfio_dump.hpp" -#include "targ-config.h" using namespace libIRDB; @@ -38,7 +40,7 @@ typedef struct elf_info { void found_string(string s, void* addr) { - char buff[s.length()+2]; + char *buff=(char*)malloc(s.length()+2); char *old_p=buff, *p; // use .data() instead of c_str(); can find multiple C-strings in one string memcpy(buff,s.data(),s.length()); @@ -402,27 +404,27 @@ void find_strings_in_data(FileIR_t* firp, elf_info_t& ei) { case SHT_REL: if(arch_ptr_bytes()==4) - step = sizeof(::Elf32_Rel); + step = sizeof(std::Elf32_Rel); else - step = sizeof(::Elf64_Rel); + step = sizeof(std::Elf64_Rel); break; case SHT_RELA: if(arch_ptr_bytes()==4) - step = sizeof(::Elf32_Rela); + step = sizeof(std::Elf32_Rela); else - step = sizeof(::Elf64_Rela); + step = sizeof(std::Elf64_Rela); break; case SHT_SYMTAB: case SHT_DYNSYM: if(arch_ptr_bytes()==4) { offset = sizeof(::Elf32_Word); - step = sizeof(::Elf32_Sym); + step = sizeof(std::Elf32_Sym); } else { offset = sizeof(::Elf64_Word); - step = sizeof(::Elf64_Sym); + step = sizeof(std::Elf64_Sym); } break; default: diff --git a/libIRDB/test/read_ehframe.cpp b/libIRDB/test/read_ehframe.cpp index 73b5324f3c2d0e9ef5129e524802ac4924b583ce..fc9cb0b456660c98d01218958337f09dd3b567c4 100644 --- a/libIRDB/test/read_ehframe.cpp +++ b/libIRDB/test/read_ehframe.cpp @@ -9,9 +9,9 @@ #include <assert.h> #include <string.h> +#include "targ-config.h" #include "elfio/elfio.hpp" #include "elfio/elfio_dump.hpp" -#include "targ-config.h" using namespace libIRDB; using namespace std; @@ -82,7 +82,7 @@ struct dwarf_cie uword length; sword CIE_id; ubyte version; - unsigned char augmentation[]; + unsigned char augmentation[1]; } __attribute__ ((packed, aligned (__alignof__ (void *)))); @@ -91,7 +91,7 @@ struct dwarf_fde { uword length; sword CIE_delta; - unsigned char pc_begin[]; + unsigned char pc_begin[1]; } __attribute__ ((packed, aligned (__alignof__ (void *)))); @@ -99,7 +99,7 @@ struct fde_vector { void *orig_data; size_t count; - struct dwarf_fde *array[]; + struct dwarf_fde *array[1]; }; struct object diff --git a/libMEDSannotation/Makefile b/libMEDSannotation/Makefile index 8eeb9bea022e83cddb938e52c3155e2962f19924..3efff213ee14dc4a17a075afcb8650564d948946 100644 --- a/libMEDSannotation/Makefile +++ b/libMEDSannotation/Makefile @@ -1,5 +1,9 @@ + +CC="cc -I/opt/csw/include" +CXX="CC -I/opt/csw/include" + all: - cd src; make + cd src;make CC=$(CC) CXX=$(CXX) clean: cd src; make clean diff --git a/libMEDSannotation/src/Makefile b/libMEDSannotation/src/Makefile index bfeb0b826f527dcecc8d7ac6abe1ef9bd581fc9b..0202d40fca3e49ad1612f2da474b76af2207b6cb 100644 --- a/libMEDSannotation/src/Makefile +++ b/libMEDSannotation/src/Makefile @@ -11,6 +11,6 @@ clean: rm -f $(OBJS) .cpp.o: - g++ -g -c -I. -I../include $< + $(CXX) -g -c -I. -I../include $< ar rc $(LIB) $@ cp $(LIB) ../../lib diff --git a/libtransform/src/Makefile b/libtransform/src/Makefile index 42a516afd53b771ba3a308d48a6ae45716a5dc56..43464bf65655c4809d69c665c3d7d68bba1c1c34 100644 --- a/libtransform/src/Makefile +++ b/libtransform/src/Makefile @@ -10,6 +10,6 @@ clean: rm -f $(OBJS) .cpp.o: - g++ -g -c -I. -I../include -I../../libIRDB/include -I../../libMEDSannotation/include -I../../beaengine/include $< + $(CXX) -g -c -I. -I../include -I../../libIRDB/include -I../../libMEDSannotation/include -I../../beaengine/include $< ar rc $(LIB) $@ cp $(LIB) ../../lib/ diff --git a/libtransform/src/integertransform.cpp b/libtransform/src/integertransform.cpp index 4328f4a9cb929bc7df18a8881ad32698acd1c531..6e1ab44d91f6d0b2d15e8786bf33e363edc20d34 100644 --- a/libtransform/src/integertransform.cpp +++ b/libtransform/src/integertransform.cpp @@ -2,6 +2,31 @@ #include "integertransform.hpp" #include "leapattern.hpp" + +/* + * Find the first occurrence of find in s, ignore case. + */ +static char * +my_strcasestr(const char* s, char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} + + // // For list of blacklisted functions, see: isBlacklisted() // @@ -2065,23 +2090,23 @@ bool IntegerTransform::isBlacklisted(Function_t *func) if (!func) return false; const char *funcName = func->GetName().c_str(); - if (/*strcasestr(funcName, "hash") || - strcasestr(funcName, "compress") || - strcasestr(funcName, "encode") || - strcasestr(funcName, "decode") || - strcasestr(funcName, "crypt") || + if (/*my_strcasestr(funcName, "hash") || + my_strcasestr(funcName, "compress") || + my_strcasestr(funcName, "encode") || + my_strcasestr(funcName, "decode") || + my_strcasestr(funcName, "crypt") || */ // haystack, needle - strcasestr(funcName, "yyparse") || - strcasestr(funcName, "yyerror") || - strcasestr(funcName, "yydestruct") || - strcasestr(funcName, "yyrestart") || - strcasestr(funcName, "yylex") || - strcasestr(funcName, "yy_") + my_strcasestr(funcName, "yyparse") || + my_strcasestr(funcName, "yyerror") || + my_strcasestr(funcName, "yydestruct") || + my_strcasestr(funcName, "yyrestart") || + my_strcasestr(funcName, "yylex") || + my_strcasestr(funcName, "yy_") /* || - strcasestr(funcName, "sub_17810") || - strcasestr(funcName, "process_active_connection") - strcasestr(funcName, "random") + my_strcasestr(funcName, "sub_17810") || + my_strcasestr(funcName, "process_active_connection") + my_strcasestr(funcName, "random") */ ) { diff --git a/libtransform/src/transform.cpp b/libtransform/src/transform.cpp index f00cda0de4df59b6592b6e1a1b2eca782fda7407..da724652e5cf5276b6a8d7336a87ede9f5222db6 100644 --- a/libtransform/src/transform.cpp +++ b/libtransform/src/transform.cpp @@ -1,5 +1,28 @@ #include "transform.hpp" +/* + * Find the first occurrence of find in s, ignore case. + */ +static char * +my_strcasestr(const char* s, char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} + #define OPTIMIZE_ASSEMBLY using namespace libTransform; @@ -467,14 +490,14 @@ bool Transform::isMultiplyInstruction(Instruction_t *p_instruction) std::string assembly = m_fileIR->LookupAssembly(p_instruction); if (assembly.length() > 0) { - return strcasestr(assembly.c_str(), "MUL") != NULL; + return my_strcasestr(assembly.c_str(), "MUL") != NULL; } DISASM disasm; p_instruction->Disassemble(disasm); // beaengine adds space at the end of the mnemonic string - return strcasestr(disasm.Instruction.Mnemonic, "MUL ") != NULL; + return my_strcasestr(disasm.Instruction.Mnemonic, "MUL ") != NULL; } // @@ -490,13 +513,13 @@ bool Transform::isAddSubNonEspInstruction(Instruction_t *p_instruction) p_instruction->Disassemble(disasm); // beaengine adds space at the end of the mnemonic string - if (strcasestr(disasm.Instruction.Mnemonic, "ADD ")) + if (my_strcasestr(disasm.Instruction.Mnemonic, "ADD ")) { return true; } - else if (strcasestr(disasm.Instruction.Mnemonic, "SUB ")) + else if (my_strcasestr(disasm.Instruction.Mnemonic, "SUB ")) { - if (strcasestr(disasm.Argument1.ArgMnemonic,"esp") && + if (my_strcasestr(disasm.Argument1.ArgMnemonic,"esp") && (disasm.Argument2.ArgType & 0xFFFF0000 & (CONSTANT_TYPE | ABSOLUTE_))) { // optimization: filter out "sub esp, K" diff --git a/tools/cover/Makefile b/tools/cover/Makefile index 794d5866fd92ce47491a0b4530c4d290b7bfadd9..ed824c84c6ab29a8692ded7352635379d5d97793 100644 --- a/tools/cover/Makefile +++ b/tools/cover/Makefile @@ -15,7 +15,6 @@ # -CC=g++ CFLAGS= -g INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include -I../../libIRDB/include/ LIBS=-L../../lib -L../../xform -lxform -lIRDB-core -lBeaEngine_s_d -lpqxx @@ -24,7 +23,7 @@ OBJS=coverage.o .SUFFIXES: .o .c .cpp .cpp.o .c.o: - $(CC) $(CFLAGS) $(INCLUDE) -c $< + $(CXX) $(CFLAGS) $(INCLUDE) -c $< all: cover @@ -34,5 +33,5 @@ clean: rm -f *.o core cover cover: $(OBJS) cover.cpp ../../lib/* - $(CC) $(CFLAGS) -o cover $(INCLUDE) cover.cpp $(OBJS) $(LIBS) + $(CXX) $(CFLAGS) -o cover $(INCLUDE) cover.cpp $(OBJS) $(LIBS) diff --git a/tools/cover/coverage.cpp b/tools/cover/coverage.cpp index d11ceba55a1b2977558f314c75a346544397437c..31981e5a23f7f7ab7320fc049b86ac7a7ad8c103 100644 --- a/tools/cover/coverage.cpp +++ b/tools/cover/coverage.cpp @@ -5,6 +5,8 @@ #include <limits.h> #include <string> #include <fstream> +#include <libgen.h> + using namespace std; using namespace libIRDB; @@ -20,7 +22,7 @@ void trim(string& str) else str.erase(str.begin(), str.end()); } -enum STR2NUM_ERROR { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE }; +enum STR2NUM_ERROR { STR2_SUCCESS, STR2_OVERFLOW, STR2_UNDERFLOW, STR2_INCONVERTIBLE }; //TODO: what if the string represents a negative number? Currently //the number will be translated into an unsigned int. I could make this @@ -32,14 +34,14 @@ STR2NUM_ERROR str2uint (unsigned int &i, char const *s, int base=0) errno = 0; l = strtoul(s, &end, base); if ((errno == ERANGE && l == ULONG_MAX) || l > UINT_MAX) { - return OVERFLOW; + return STR2_OVERFLOW; } if (*s == '\0' || *end != '\0') { - return INCONVERTIBLE; + return STR2_INCONVERTIBLE; } i = l; - return SUCCESS; + return STR2_SUCCESS; } @@ -80,7 +82,7 @@ void coverage::parse_coverage_file(ifstream &coverage_file) unsigned int uint_addr; - assert(str2uint(uint_addr,addr.c_str())==SUCCESS); + assert(str2uint(uint_addr,addr.c_str())==STR2_SUCCESS); coverage_map[file].coverage[uint_addr]=uint_addr; } @@ -97,7 +99,7 @@ file_coverage* coverage::find_file_coverage(string url) //the shared objects are registered, but this might cause //issues if shared objects have the same name. - key=string(basename(key.c_str())); + key=string(basename((char*)key.c_str())); if(key.empty()) continue; diff --git a/tools/meds2pdb/Makefile b/tools/meds2pdb/Makefile index 9638d39d5b5c10ac4a92d77cd0e181d8d21c671c..832fd0b6e6dbdd0c8d5c8325ed7d0e0ce02b2a55 100644 --- a/tools/meds2pdb/Makefile +++ b/tools/meds2pdb/Makefile @@ -15,7 +15,6 @@ # -CC=g++ CFLAGS= -g INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include LIBS=-L../../lib -lxform -lBeaEngine_s_d -lpq -lpqxx @@ -23,7 +22,7 @@ LIBS=-L../../lib -lxform -lBeaEngine_s_d -lpq -lpqxx .SUFFIXES: .o .c .cpp .cpp.o .c.o: - $(CC) $(CFLAGS) $(INCLUDE) -c $< + $(CXX) $(CFLAGS) $(INCLUDE) -c $< all: meds2pdb @@ -33,5 +32,5 @@ clean: rm -f *.o core meds2pdb meds2pdb: $(OBJS) meds2pdb.cpp ../../lib/*.a - $(CC) $(CFLAGS) -o meds2pdb $(INCLUDE) meds2pdb.cpp $(OBJS) $(LIBS) + $(CXX) $(CFLAGS) -o meds2pdb $(INCLUDE) meds2pdb.cpp $(OBJS) $(LIBS) diff --git a/tools/memcover/Makefile b/tools/memcover/Makefile index bdce8147b05ea3cc9fdcc32922b675615c51515b..2786ca172dbc6615f3163778dcb9173899dc7037 100644 --- a/tools/memcover/Makefile +++ b/tools/memcover/Makefile @@ -17,8 +17,8 @@ PROGS=memcover.exe -CC=g++ -CFLAGS= -g -O3 -Wall +CFLAGS= -g +# -O3 -Wall INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include -I../../libIRDB/include/ -I../../libMEDSannotation/include/ -I../../libtransform/include/ LIBS=-L../../lib -L../../xform -lxform -lELFIO -L../../libIRDB/lib/ -lIRDB-core -lIRDB-cfg -L../../beaengine/lib/Linux.gnu.Debug -lBeaEngine_s_d -lpqxx -L../../libMEDSannotation/lib -lMEDSannotation -L../../libtransform/lib -ltransform OBJS=transformutils.o @@ -29,14 +29,14 @@ all: memcover $(OBJS) $(PROGS) echo memcover build complete .o: $< - $(CC) -g -c $@ + $(CXX) -g -c $@ .cpp.exe: $< - $(CC) -g $< $(INCLUDE) $(LIBS) $(OBJS) -o $@ + $(CXX) -g $< $(INCLUDE) $(LIBS) $(OBJS) -o $@ clean: rm -f *.o core $(PROGS) memcover: - $(CC) $(CFLAGS) memcover.cpp General_Utility.cpp Rewrite_Utility.cpp $(INCLUDE) $(LIBS) -o memcover.exe + $(CXX) $(CFLAGS) memcover.cpp General_Utility.cpp Rewrite_Utility.cpp $(INCLUDE) $(LIBS) -o memcover.exe diff --git a/tools/spasm/Makefile b/tools/spasm/Makefile index 32ecc91d60ef632fb38e7a6496d0e581ca1fd8e2..5a1115c4f2d8251bb701c4b6d32737897a0cdbce 100644 --- a/tools/spasm/Makefile +++ b/tools/spasm/Makefile @@ -16,14 +16,14 @@ # # -CC=g++ -CFLAGS= -Wall -g# -DUBUNTU -Wall -O3 +CFLAGS= -g +# -DUBUNTU -Wall -O3 INCLUDE=-I. -I../../include -I../../xform LIBS=-L../../xform -lxform .cpp.o .c.o: - $(CC) $(CFLAGS) $(INCLUDE) -c $< + $(CXX) $(CFLAGS) $(INCLUDE) -c $< all: spasm echo spasm build complete @@ -32,4 +32,4 @@ clean: rm -f *.o core spasm *.map *.bspri *.asm *.bin spasm: $(OBJS) spasm.cpp Makefile spasm.h spasm_main.cpp ben_lib.cpp ben_lib.h ../../xform/libxform.a - $(CC) -o spasm $(INCLUDE) $(CFLAGS) spasm_main.cpp spasm.cpp ben_lib.cpp $(OBJS) $(LIBS) + $(CXX) -o spasm $(INCLUDE) $(CFLAGS) spasm_main.cpp spasm.cpp ben_lib.cpp $(OBJS) $(LIBS) diff --git a/tools/transforms/General_Utility.cpp b/tools/transforms/General_Utility.cpp index 70b27ed4b63239b10a8d124efbdfedb29ae0f91d..e2eb56658d8d937a153a4f75b5be9db50350afb8 100644 --- a/tools/transforms/General_Utility.cpp +++ b/tools/transforms/General_Utility.cpp @@ -12,16 +12,16 @@ STR2NUM_ERROR str2int (int &i, char const *s, int base) errno = 0; l = strtol(s, &end, base); if ((errno == ERANGE && l == LONG_MAX) || l > INT_MAX) { - return OVERFLOW; + return STR2_OVERFLOW; } if ((errno == ERANGE && l == LONG_MIN) || l < INT_MIN) { - return UNDERFLOW; + return STR2_UNDERFLOW; } if (*s == '\0' || *end != '\0') { - return INCONVERTIBLE; + return STR2_INCONVERTIBLE; } i = l; - return SUCCESS; + return STR2_SUCCESS; } //TODO: what if the string represents a negative number? Currently @@ -34,11 +34,11 @@ STR2NUM_ERROR str2uint (unsigned int &i, char const *s, int base) errno = 0; l = strtoul(s, &end, base); if ((errno == ERANGE && l == ULONG_MAX) || l > UINT_MAX) { - return OVERFLOW; + return STR2_OVERFLOW; } if (*s == '\0' || *end != '\0') { - return INCONVERTIBLE; + return STR2_INCONVERTIBLE; } i = l; - return SUCCESS; + return STR2_SUCCESS; } diff --git a/tools/transforms/General_Utility.hpp b/tools/transforms/General_Utility.hpp index a40ffb9855cee2aa6993bc469006385720419108..437ebf75b532822ff6d2b9aeb6a9b96037db055f 100644 --- a/tools/transforms/General_Utility.hpp +++ b/tools/transforms/General_Utility.hpp @@ -1,7 +1,7 @@ #ifndef _GENERAL_UTILITY #define _GENERAL_UTILITY -enum STR2NUM_ERROR { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE }; +enum STR2NUM_ERROR { STR2_SUCCESS, STR2_OVERFLOW, STR2_UNDERFLOW, STR2_INCONVERTIBLE }; STR2NUM_ERROR str2int (int &i, char const *s, int base = 0); STR2NUM_ERROR str2uint (unsigned int &i, char const *s, int base = 0); diff --git a/tools/transforms/Makefile b/tools/transforms/Makefile index e5b38f5ae83c33ea40f14287fbe3dce97641c972..9c02ee78a11231e3db945125d9cf870bfbe9e28e 100644 --- a/tools/transforms/Makefile +++ b/tools/transforms/Makefile @@ -17,10 +17,10 @@ PROGS=p1transform.exe nulltransform.exe integertransformdriver.exe -CC=g++ -CFLAGS= -g -Wall +CFLAGS= -g +# -Wall INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include -I../../libIRDB/include/ -I../../libMEDSannotation/include/ -I../../libtransform/include/ -LIBS=-L../../lib -lxform -lIRDB-core -lIRDB-cfg -lBeaEngine_s_d -lpqxx -lMEDSannotation -ltransform +LIBS=-L../../lib -lxform -lIRDB-core -lIRDB-cfg -lBeaEngine_s_d -L /opt/csw/lib/ -lpqxx -lMEDSannotation -ltransform OBJS=transformutils.o @@ -36,17 +36,17 @@ all: p1transform.exe pntransform.exe $(OBJS) $(PROGS) $(all_objs): *hpp .cpp.o: PNStackLayoutInference.hpp *.hpp - $(CC) $(INCLUDE) $(CFLAGS) -g -c $< + $(CXX) $(INCLUDE) $(CFLAGS) -g -c $< .cpp.exe: - $(CC) -g $< $(INCLUDE) $(LIBS) $(OBJS) -o $@ + $(CXX) -g $< $(INCLUDE) $(LIBS) $(OBJS) -o $@ clean: rm -f *.o core $(PROGS) pntransform.exe: $(all_objs) ../../lib/*.a - $(CC) $(CFLAGS) $(all_objs) $(INCLUDE) $(LIBS) -o pntransform.exe + $(CXX) $(CFLAGS) $(all_objs) $(INCLUDE) $(LIBS) -o pntransform.exe p1transform.exe: pntransform.exe diff --git a/tools/transforms/OffsetInference.cpp b/tools/transforms/OffsetInference.cpp index 220d4437619da44aebe3036989800e8c63200a84..347cfc2d4e5be5d626768237fb2d325421e4d90f 100644 --- a/tools/transforms/OffsetInference.cpp +++ b/tools/transforms/OffsetInference.cpp @@ -100,7 +100,7 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func) // bool has_frame_pointer = false; int max = PNRegularExpressions::MAX_MATCHES; - regmatch_t pmatch[max]; + regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(pmatch)); memset(pmatch, 0,sizeof(regmatch_t) * max); assert(out_args_size >=0); @@ -219,7 +219,7 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func) //find the indirect branch target instruction, and reset entry to this instruction, then continue execution of the loop. int target_addr_offset; - assert(str2int(target_addr_offset, matched.c_str())==SUCCESS); + assert(str2int(target_addr_offset, matched.c_str())==STR2_SUCCESS); //TODO: it is better to make a map of ind branch targets, but this efficient enough for now. @@ -281,7 +281,7 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func) matched = disasm_str.substr(pmatch[1].rm_so,mlen); //extract K //stack_frame_size = strtol(matched.c_str(),NULL,0); - if(str2uint(stack_frame_size, matched.c_str())!= SUCCESS) + if(str2uint(stack_frame_size, matched.c_str())!= STR2_SUCCESS) { //If this occurs, then the found stack size is not a //constant integer, so it must be a register. @@ -337,7 +337,8 @@ void OffsetInference::FindAllOffsets(Function_t *func) //int out_args_size; int max = PNRegularExpressions::MAX_MATCHES; - regmatch_t pmatch[max]; + //regmatch_t pmatch[max]; + regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(pmatch)); memset(pmatch, 0,sizeof(regmatch_t) * max); unsigned int stack_frame_size = 0; unsigned int saved_regs_size = 0; @@ -538,7 +539,7 @@ else matched = disasm_str.substr(pmatch[1].rm_so,mlen); //extract K unsigned int scheck; - if(str2uint(scheck, matched.c_str()) != SUCCESS) + if(str2uint(scheck, matched.c_str()) != STR2_SUCCESS) { //If this occurs, then the found stack size is not a //constant integer, so it must be a register. diff --git a/tools/transforms/PNIrdbManager.hpp b/tools/transforms/PNIrdbManager.hpp index 34b494866f8565d6a3f9d819089a18211efe542c..66cd5dda5e1878e497b572a0618dfe62f3f1da07 100644 --- a/tools/transforms/PNIrdbManager.hpp +++ b/tools/transforms/PNIrdbManager.hpp @@ -9,8 +9,8 @@ class PNIrdbManager public: enum IRSource { - PEASOUP, - DWARF, + IRS_PEASOUP, + IRS_DWARF }; PNIrdbManager(libIRDB::db_id_t variant_db_id); diff --git a/tools/transforms/PNTransformDriver.cpp b/tools/transforms/PNTransformDriver.cpp index 80b297fe6f84b7831842bc091cfbe8853450f249..e3844c90653a51daed7ce5724a757c0639bb95c1 100644 --- a/tools/transforms/PNTransformDriver.cpp +++ b/tools/transforms/PNTransformDriver.cpp @@ -10,9 +10,30 @@ #include "globals.h" #include <libIRDB-cfg.hpp> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <libgen.h> +#include <sys/types.h> +#include <sys/wait.h> + + using namespace std; using namespace libIRDB; +char* get_current_dir_name(void) +{ + char* pwd = getenv("PWD"); + char tmp[PATH_MAX]; + struct stat a,b; + if (pwd && !stat(".",&a) && !stat(pwd,&b) && + a.st_dev==b.st_dev && a.st_ino==b.st_ino) + return strdup(pwd); + if (getcwd(tmp,sizeof(tmp))) + return strdup(tmp); + return 0; +} + //TODO: this var is a hack for TNE extern map<Function_t*, set<Instruction_t*> > inserted_instr; extern map<Function_t*, set<AddressID_t*> > inserted_addr; @@ -600,7 +621,7 @@ ELFIO::dump::section_headers(cout,*elfiop); //TODO: basename is only used as a hack //because of the way the url is stored in the db. //The url should be fixed to be the absolute path. - key=string(basename(key.c_str())); + key=string(basename((char*)key.c_str())); if(key.empty()) continue; @@ -755,12 +776,12 @@ bool check_for_push_pop_coherence(Function_t *func) // stack first. Also handy as this allows "fixed" calls to be ignored. // but, since exits with 0 pops aren't in the map, we don't need an explicit check for them. for( - map<Instruction_t*,int>::const_iterator it=pop_count_per_exit.begin(); + map<Instruction_t* ,int>::iterator it=pop_count_per_exit.begin(); it!=pop_count_per_exit.end(); ++it ) { - pair<Instruction_t*,int> map_pair=*it; + pair<Instruction_t*const,int> map_pair=*it; Instruction_t* insn=map_pair.first; assert(insn); DISASM d; @@ -1200,7 +1221,7 @@ void PNTransformDriver::GenerateTransformsHidden(map<string,double> &file_covera cerr<<"Functions to shuffle validate: "<<shuffle_validate_funcs.size()<<endl; ShuffleValidation(shuffle_validate_funcs); - if(!Validate(NULL,string(basename(orig_virp->GetFile()->GetURL().c_str()))+"_accum")) + if(!Validate(NULL,string(basename((char*)orig_virp->GetFile()->GetURL().c_str()))+"_accum")) { cerr<<"TEST ERROR: File: "<<orig_virp->GetFile()->GetURL()<<" does not pass accumulation validation, ignoring the file for now."<<endl; @@ -1871,7 +1892,7 @@ bool PNTransformDriver::Canary_Rewrite(PNStackLayout *orig_layout, Function_t *f //bool stack_alloc = false; int max = PNRegularExpressions::MAX_MATCHES; - regmatch_t pmatch[max]; + regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(regmatch_t)); memset(pmatch, 0,sizeof(regmatch_t) * max); for( @@ -1908,7 +1929,7 @@ bool PNTransformDriver::Canary_Rewrite(PNStackLayout *orig_layout, Function_t *f matched = disasm_str.substr(pmatch[1].rm_so,mlen); //extract K unsigned int ssize; - if(str2uint(ssize, matched.c_str()) != SUCCESS) + if(str2uint(ssize, matched.c_str()) != STR2_SUCCESS) { //If this occurs, then the found stack size is not a //constant integer, so it must be a register. @@ -2097,7 +2118,8 @@ int PNTransformDriver::prologue_offset_to_actual_offset(ControlFlowGraph_t* cfg, return offset; int max = PNRegularExpressions::MAX_MATCHES; - regmatch_t pmatch[max]; + //regmatch_t pmatch[max]; + regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(regmatch_t)); /* check for a stack alloc */ if(regexec(&(pn_regex->regex_stack_alloc), d.CompleteInstr, 5, pmatch, 0)==0) @@ -2110,7 +2132,7 @@ int PNTransformDriver::prologue_offset_to_actual_offset(ControlFlowGraph_t* cfg, matched = disasm_str.substr(pmatch[1].rm_so,mlen); //extract K unsigned int ssize; - if(str2uint(ssize, matched.c_str()) != SUCCESS) + if(str2uint(ssize, matched.c_str()) != STR2_SUCCESS) { return offset; } @@ -2149,7 +2171,8 @@ inline bool PNTransformDriver::Instruction_Rewrite(PNStackLayout *layout, Instru esp_reg="rsp"; int max = PNRegularExpressions::MAX_MATCHES; - regmatch_t pmatch[max]; + //regmatch_t pmatch[max]; + regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(regmatch_t)); memset(pmatch, 0,sizeof(regmatch_t) * max); string matched=""; @@ -2197,7 +2220,7 @@ inline bool PNTransformDriver::Instruction_Rewrite(PNStackLayout *layout, Instru matched = disasm_str.substr(pmatch[1].rm_so,mlen); //extract K unsigned int ssize; - if(str2uint(ssize, matched.c_str()) != SUCCESS) + if(str2uint(ssize, matched.c_str()) != STR2_SUCCESS) { //If this occurs, then the found stack size is not a //constant integer, so it must be a register. @@ -2684,7 +2707,7 @@ bool PNTransformDriver::WriteStackIRToDB() } else { - irdb_manager.DeleteSource(PNIrdbManager::PEASOUP); + irdb_manager.DeleteSource(PNIrdbManager::IRS_PEASOUP); } std::map< std::string,std::vector<PNStackLayout*> >::const_iterator it = @@ -2704,7 +2727,7 @@ bool PNTransformDriver::WriteStackIRToDB() layouts[laynum]->GetFunctionName(), mem_objects[j]->GetOffset(), mem_objects[j]->GetSize(), - PNIrdbManager::PEASOUP); + PNIrdbManager::IRS_PEASOUP); // DEBUG cerr<< "\tOffset = " << mem_objects[j]->GetOffset() << " Size = "<<mem_objects[j]->GetSize() << endl; diff --git a/tools/transforms/nulltransform.cpp b/tools/transforms/nulltransform.cpp index 06026a4ef049e495ba72ca143d639393b34ba981..4ede4869b111cce8ec684dd8b69a528acfadb97f 100644 --- a/tools/transforms/nulltransform.cpp +++ b/tools/transforms/nulltransform.cpp @@ -1,6 +1,12 @@ #include <iostream> +#include "targ-config.h" + +#include "elfio/elfio.hpp" +#include "elfio/elfio_dump.hpp" + #include "null_transform.h" + int main(int argc, char **argv) { if (argc < 3) diff --git a/xform/Makefile b/xform/Makefile index b5185c6219c90abfa951d8571a236c9164330acf..1f5261645a578b9d113656875f2f02a339fd9a7e 100644 --- a/xform/Makefile +++ b/xform/Makefile @@ -13,7 +13,7 @@ # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. # -CC=g++ +CC=$(CXX) CFLAGS= -DUBUNTU -g DIR=.. INCLUDEDIR=${DIR}/include diff --git a/xform/elfreader.cpp b/xform/elfreader.cpp index 686da4a71f9e098cea0fe869e4635d6e8e097f19..c2e2ccd18e5ef2b5502ee98b990ef87e969d30ea 100644 --- a/xform/elfreader.cpp +++ b/xform/elfreader.cpp @@ -1,5 +1,10 @@ #include <iostream> #include <string.h> +#include "targ-config.h" + +#include "elfio/elfio.hpp" +#include "elfio/elfio_dump.hpp" + #include "elfreader.h" using namespace std; diff --git a/xform/null_transform.cpp b/xform/null_transform.cpp index 5207b0b0b6e98da4a162c1147caa1959471ca2c2..49c8f2469816e3dc21366b93dcace5807fb845d1 100644 --- a/xform/null_transform.cpp +++ b/xform/null_transform.cpp @@ -1,8 +1,15 @@ #include <iostream> +#include "targ-config.h" + +#include "elfio/elfio.hpp" +#include "elfio/elfio_dump.hpp" + #include "null_transform.h" #include "stackref_hash.h" + + using namespace wahoo; // diff --git a/xform/rewriter.cpp b/xform/rewriter.cpp index fcc486c7428779a97aeeadaf42543782b650c3e1..b5cba15c03b51116e270ff190ca4609e956988c2 100644 --- a/xform/rewriter.cpp +++ b/xform/rewriter.cpp @@ -3,10 +3,18 @@ #include <set> #include <stdlib.h> + + #include "beaengine/BeaEngine.h" -#include "rewriter.h" #include "all.h" +#include "targ-config.h" +#include "elfio/elfio.hpp" +#include "elfio/elfio_dump.hpp" + + +#include "rewriter.h" + using namespace std; @@ -629,7 +637,7 @@ void Rewriter::readXrefsFile(char p_filename[]) void Rewriter::readElfFile(char p_filename[]) { char buf[1000]; - sprintf(buf, "objdump -d --prefix-addresses %s | grep \"^[0-9]\"", p_filename); + sprintf(buf, "gobjdump -d --prefix-addresses %s | grep \"^[0-9]\"", p_filename); FILE* pin=popen(buf, "r"); int addr; diff --git a/xform/rewriter.h b/xform/rewriter.h index 9f8715f7cc53e4e7f951c3163aec93b793f85834..d2726b6fb9ed6b57efd18a51c23277fcd8d4af2d 100644 --- a/xform/rewriter.h +++ b/xform/rewriter.h @@ -1,4 +1,8 @@ #include <map> +#include "targ-config.h" +#include "elfio/elfio.hpp" +#include "elfio/elfio_dump.hpp" + #include "elfreader.h" #include "function_descriptor.h"