Changeset 1654
- Timestamp:
- 07/16/08 19:42:16 (3 months ago)
- Files:
-
- libemu/trunk/include/emu/emu_hashtable.h (modified) (1 diff)
- libemu/trunk/src/emu_hashtable.c (modified) (1 diff)
- libemu/trunk/src/emu_shellcode.c (modified) (2 diffs)
- libemu/trunk/src/environment/linux/emu_env_linux.c (modified) (2 diffs)
- libemu/trunk/src/environment/win32/emu_env_w32_dll.c (modified) (2 diffs)
- libemu/trunk/tools/sctest/Makefile.am (modified) (2 diffs)
- libemu/trunk/tools/sctest/dot.c (modified) (1 diff)
- libemu/trunk/tools/sctest/sctestmain.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libemu/trunk/include/emu/emu_hashtable.h
r1507 r1654 161 161 bool emu_hashtable_delete(struct emu_hashtable *eh, void *key); 162 162 163 164 uint32_t emu_hashtable_string_hash(void *data); 165 bool emu_hashtable_string_cmp(void *a, void *b); 166 167 uint32_t emu_hashtable_ptr_hash(void *data); 168 bool emu_hashtable_ptr_cmp(void *a, void *b); 169 170 163 171 #endif // EMU_HASHTABLE_H libemu/trunk/src/emu_hashtable.c
r1507 r1654 211 211 free(ehbi); 212 212 } 213 214 215 216 /** 217 * string hashing function to avoid duplicate code 218 * algo is djb2 taken from http://www.cse.yorku.ca/~oz/hash.html 219 * 220 * @param data the string to hash 221 * 222 * @return the hash 223 */ 224 uint32_t emu_hashtable_string_hash(void *key) 225 { 226 #ifdef LSOD_HASH 227 uint32_t hash = 0; 228 char *c = (char *)key; 229 230 while (*c != 0) 231 { 232 hash = hash << 19 | hash >> 13; 233 hash += *c; 234 c++; 235 } 236 237 return hash; 238 #else 239 unsigned char *str = key; 240 unsigned long hash = 5381; 241 int c; 242 243 while ( (c = *str++) != 0 ) 244 hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 245 246 return hash; 247 #endif 248 } 249 250 bool emu_hashtable_string_cmp(void *a, void *b) 251 { 252 if ( strcmp(a, b) == 0 ) 253 return true; 254 255 return false; 256 } 257 258 uint32_t emu_hashtable_ptr_hash(void *key) 259 { 260 uint32_t ukey = (uint32_t)key; 261 ukey++; 262 return ukey; 263 } 264 265 bool emu_hashtable_ptr_cmp(void *a, void *b) 266 { 267 if ( (uint32_t)a == (uint32_t)b ) 268 return true; 269 270 return false; 271 } 272 libemu/trunk/src/emu_shellcode.c
r1607 r1654 52 52 53 53 54 bool cmp_uint32_t(void *a, void *b)55 {56 if ( (uint32_t)a == (uint32_t)b )57 return true;58 59 return false;60 }61 62 uint32_t hash_uint32_t(void *key)63 {64 uint32_t ukey = (uint32_t)key;65 ukey++;66 return ukey;67 }68 69 70 54 int tested_positions_cmp(struct emu_list_item *a, struct emu_list_item *b) 71 55 { … … 386 370 emu_memory_mode_rw(emu_memory_get(e)); 387 371 388 struct emu_hashtable *eh = emu_hashtable_new(size+4/4, hash_uint32_t, cmp_uint32_t);372 struct emu_hashtable *eh = emu_hashtable_new(size+4/4, emu_hashtable_ptr_hash, emu_hashtable_ptr_cmp); 389 373 struct emu_list_item *eli; 390 374 // struct emu_env_w32 *env = emu_env_w32_new(e); libemu/trunk/src/environment/linux/emu_env_linux.c
r1607 r1654 36 36 #include "emu/environment/linux/env_linux_syscalls.h" 37 37 38 extern uint32_t dll_export_fnname_hash(void *key);39 extern bool dll_export_fnname_cmp(void *a, void *b);40 41 38 struct emu_env_linux *emu_env_linux_new(struct emu *e) 42 39 { … … 45 42 eel->emu = e; 46 43 47 eel->syscall_hooks_by_name = emu_hashtable_new(256, dll_export_fnname_hash, dll_export_fnname_cmp);44 eel->syscall_hooks_by_name = emu_hashtable_new(256, emu_hashtable_string_hash, emu_hashtable_string_cmp); 48 45 int i; 49 46 eel->syscall_hookx = malloc(sizeof(syscall_hooks)); libemu/trunk/src/environment/win32/emu_env_w32_dll.c
r1607 r1654 52 52 } 53 53 54 bool dll_export_fnptr_cmp(void *a, void *b)55 {56 if ((uint32_t)a == (uint32_t)b)57 return true;58 59 return false;60 }61 62 uint32_t dll_export_fnptr_hash(void *key)63 {64 uint32_t ukey = (uint32_t)key;65 ukey++;66 return ukey;67 }68 69 70 bool dll_export_fnname_cmp(void *a, void *b)71 {72 if (strcmp((char *)a, (char *)b) == 0)73 return true;74 75 return false;76 }77 78 #define HASH_KEY 1379 uint32_t dll_export_fnname_hash(void *key)80 {81 uint32_t hash = 0;82 char *c = (char *)key;83 /*84 while ( *c != 0 )85 {86 asm ("ror DWORD hash,13");87 88 hash += *c++;89 }90 */91 while (*c != 0)92 {93 hash = hash << 19 | hash >> 13;94 hash += *c;95 c++;96 }97 98 return hash;99 }100 101 102 54 void emu_env_w32_dll_exports_copy(struct emu_env_w32_dll *to,struct emu_env_w32_dll_export *from) 103 55 { … … 113 65 114 66 115 to->exports_by_fnptr = emu_hashtable_new(size, dll_export_fnptr_hash, dll_export_fnptr_cmp);116 to->exports_by_fnname = emu_hashtable_new(size, dll_export_fnname_hash, dll_export_fnname_cmp);67 to->exports_by_fnptr = emu_hashtable_new(size, emu_hashtable_ptr_hash,emu_hashtable_ptr_cmp); 68 to->exports_by_fnname = emu_hashtable_new(size, emu_hashtable_string_hash, emu_hashtable_string_cmp); 117 69 118 70 for (i=0;from[i].fnname != 0; i++) libemu/trunk/tools/sctest/Makefile.am
r1653 r1654 11 11 sctest_LDADD = ../../src/libemu.la 12 12 sctest_SOURCES = dot.c 13 sctest_SOURCES = dot.h13 sctest_SOURCES += dot.h 14 14 sctest_SOURCES += sctestmain.c 15 15 sctest_SOURCES += sctestmain.h … … 18 18 sctest_SOURCES += userhooks.c 19 19 sctest_SOURCES += userhooks.h 20 #sctest_SOURCES += nanny.c 21 #sctest_SOURCES += nanny.h 22 libemu/trunk/tools/sctest/dot.c
r1653 r1654 119 119 120 120 struct emu_graph *sgraph = emu_graph_new(); 121 struct emu_hashtable *ht = emu_hashtable_new(2047, hash,cmp);121 struct emu_hashtable *ht = emu_hashtable_new(2047, emu_hashtable_ptr_hash, emu_hashtable_ptr_cmp); 122 122 123 123 struct emu_vertex *nev; libemu/trunk/tools/sctest/sctestmain.c
r1653 r1654 118 118 119 119 120 bool cmp(void *a, void *b)121 {122 if ( (uint32_t)a == (uint32_t)b )123 return true;124 125 return false;126 }127 128 uint32_t hash(void *key)129 {130 uint32_t ukey = (uint32_t)key;131 ukey++;132 return ukey;133 }134 135 bool string_cmp(void *a, void *b)136 {137 if ( strcmp(a, b) )138 return true;139 140 return false;141 }142 143 uint32_t string_hash(void *key)144 {145 uint32_t hash = 0;146 char *c = (char *)key;147 uint8_t num = 0x13;148 149 while (*c != 0)150 {151 hash = hash << (32-num) | hash >> (num);152 // hash = hash >> (32-num) | hash << (num);153 hash += *c;154 c++;155 }156 157 return hash;158 }159 160 161 162 163 120 int graph_draw(struct emu_graph *graph); 164 121 … … 252 209 { 253 210 graph = emu_graph_new(); 254 eh = emu_hashtable_new(2047, hash,cmp);211 eh = emu_hashtable_new(2047, emu_hashtable_ptr_hash, emu_hashtable_ptr_cmp); 255 212 } 256 213 … … 803 760 opts.offset = 0; 804 761 805 opts.override.commands.commands = emu_hashtable_new(16, string_hash,string_cmp);762 opts.override.commands.commands = emu_hashtable_new(16, emu_hashtable_string_hash, emu_hashtable_string_cmp); 806 763 807 764 while ( 1 )
