diff options
-rw-r--r-- | src/common/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/common/Makefile.in | 4 | ||||
-rw-r--r-- | src/common/des.c | 218 | ||||
-rw-r--r-- | src/common/des.h | 15 | ||||
-rw-r--r-- | src/common/grfio.c | 186 | ||||
-rw-r--r-- | src/map/Makefile.in | 4 | ||||
-rw-r--r-- | src/tool/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/tool/Makefile.in | 4 | ||||
-rw-r--r-- | vcproj-10/map-server_sql.vcxproj.filters | 3 | ||||
-rw-r--r-- | vcproj-10/map-server_txt.vcxproj.filters | 3 | ||||
-rw-r--r-- | vcproj-9/map-server_sql.vcproj | 8 | ||||
-rw-r--r-- | vcproj-9/map-server_txt.vcproj | 8 | ||||
-rw-r--r-- | vcproj-9/mapcache.vcproj | 8 |
13 files changed, 337 insertions, 128 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index ea8ce6b71..3f04e5b04 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -60,6 +60,7 @@ set( COMMON_BASE_HEADERS ${COMMON_ALL_HEADERS} "${COMMON_SOURCE_DIR}/core.h" "${COMMON_SOURCE_DIR}/db.h" + "${COMMON_SOURCE_DIR}/des.h" "${COMMON_SOURCE_DIR}/ers.h" "${COMMON_SOURCE_DIR}/grfio.h" "${COMMON_SOURCE_DIR}/lock.h" @@ -78,6 +79,7 @@ set( COMMON_BASE_HEADERS set( COMMON_BASE_SOURCES "${COMMON_SOURCE_DIR}/core.c" "${COMMON_SOURCE_DIR}/db.c" + "${COMMON_SOURCE_DIR}/des.c" "${COMMON_SOURCE_DIR}/ers.c" "${COMMON_SOURCE_DIR}/grfio.c" "${COMMON_SOURCE_DIR}/lock.c" diff --git a/src/common/Makefile.in b/src/common/Makefile.in index 37606dde2..9e92a8886 100644 --- a/src/common/Makefile.in +++ b/src/common/Makefile.in @@ -2,11 +2,11 @@ COMMON_OBJ = obj_all/core.o obj_all/socket.o obj_all/timer.o obj_all/db.o obj_all/plugins.o obj_all/lock.o \ obj_all/nullpo.o obj_all/malloc.o obj_all/showmsg.o obj_all/strlib.o obj_all/utils.o \ obj_all/grfio.o obj_all/mapindex.o obj_all/ers.o obj_all/md5calc.o \ - obj_all/minicore.o obj_all/minisocket.o obj_all/minimalloc.o obj_all/random.o + obj_all/minicore.o obj_all/minisocket.o obj_all/minimalloc.o obj_all/random.o obj_all/des.o COMMON_H = svnversion.h mmo.h plugin.h version.h \ core.h socket.h timer.h db.h plugins.h lock.h \ nullpo.h malloc.h showmsg.h strlib.h utils.h \ - grfio.h mapindex.h ers.h md5calc.h random.h + grfio.h mapindex.h ers.h md5calc.h random.h des.h COMMON_SQL_OBJ = obj_sql/sql.o COMMON_SQL_H = sql.h diff --git a/src/common/des.c b/src/common/des.c new file mode 100644 index 000000000..67a3a38d1 --- /dev/null +++ b/src/common/des.c @@ -0,0 +1,218 @@ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder +#include "../common/cbasetypes.h" +#include "../common/des.h" + + +/// DES (Data Encryption Standard) algorithm, modified version. +/// @see http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=5099. +/// @see http://en.wikipedia.org/wiki/Data_Encryption_Standard +/// @see http://en.wikipedia.org/wiki/DES_supplementary_material + + +/// Bitmask for accessing individual bits of a byte. +static const uint8_t mask[8] = { + 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 +}; + + +/// Initial permutation (IP). +static void IP(BIT64* src) +{ + BIT64 tmp = {0}; + + static const uint8_t ip_table[64] = { + 58, 50, 42, 34, 26, 18, 10, 2, + 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, + 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, + 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, + 63, 55, 47, 39, 31, 23, 15, 7, + }; + + size_t i; + for( i = 0; i < ARRAYLENGTH(ip_table); ++i ) + { + uint8_t j = ip_table[i] - 1; + if( src->b[(j >> 3) & 7] & mask[j & 7] ) + tmp .b[(i >> 3) & 7] |= mask[i & 7]; + } + + *src = tmp; +} + + +/// Final permutation (IP^-1). +static void FP(BIT64* src) +{ + BIT64 tmp = {0}; + + static const uint8_t fp_table[64] = { + 40, 8, 48, 16, 56, 24, 64, 32, + 39, 7, 47, 15, 55, 23, 63, 31, + 38, 6, 46, 14, 54, 22, 62, 30, + 37, 5, 45, 13, 53, 21, 61, 29, + 36, 4, 44, 12, 52, 20, 60, 28, + 35, 3, 43, 11, 51, 19, 59, 27, + 34, 2, 42, 10, 50, 18, 58, 26, + 33, 1, 41, 9, 49, 17, 57, 25, + }; + + size_t i; + for( i = 0; i < ARRAYLENGTH(fp_table); ++i ) + { + uint8_t j = fp_table[i] - 1; + if( src->b[(j >> 3) & 7] & mask[j & 7] ) + tmp .b[(i >> 3) & 7] |= mask[i & 7]; + } + + *src = tmp; +} + + +/// Expansion (E). +/// Expands upper four 8-bits (32b) into eight 6-bits (48b). +static void E(BIT64* src) +{ + BIT64 tmp = {0}; + +if( false ) +{// original + static const uint8_t expand_table[48] = { + 32, 1, 2, 3, 4, 5, + 4, 5, 6, 7, 8, 9, + 8, 9, 10, 11, 12, 13, + 12, 13, 14, 15, 16, 17, + 16, 17, 18, 19, 20, 21, + 20, 21, 22, 23, 24, 25, + 24, 25, 26, 27, 28, 29, + 28, 29, 30, 31, 32, 1, + }; + + size_t i; + for( i = 0; i < ARRAYLENGTH(expand_table); ++i ) + { + uint8_t j = expand_table[i] - 1; + if( src->b[j / 8 + 4] & mask[j % 8] ) + tmp .b[i / 6 + 0] |= mask[i % 6]; + } +} +else +{// optimized + tmp.b[0] = ((src->b[7]<<5) | (src->b[4]>>3)) & 0x3f; // ..0 vutsr + tmp.b[1] = ((src->b[4]<<1) | (src->b[5]>>7)) & 0x3f; // ..srqpo n + tmp.b[2] = ((src->b[4]<<5) | (src->b[5]>>3)) & 0x3f; // ..o nmlkj + tmp.b[3] = ((src->b[5]<<1) | (src->b[6]>>7)) & 0x3f; // ..kjihg f + tmp.b[4] = ((src->b[5]<<5) | (src->b[6]>>3)) & 0x3f; // ..g fedcb + tmp.b[5] = ((src->b[6]<<1) | (src->b[7]>>7)) & 0x3f; // ..cba98 7 + tmp.b[6] = ((src->b[6]<<5) | (src->b[7]>>3)) & 0x3f; // ..8 76543 + tmp.b[7] = ((src->b[7]<<1) | (src->b[4]>>7)) & 0x3f; // ..43210 v +} + + *src = tmp; +} + + +/// Transposition (P-BOX). +static void TP(BIT64* src) +{ + BIT64 tmp = {0}; + + static const uint8_t tp_table[32] = { + 16, 7, 20, 21, + 29, 12, 28, 17, + 1, 15, 23, 26, + 5, 18, 31, 10, + 2, 8, 24, 14, + 32, 27, 3, 9, + 19, 13, 30, 6, + 22, 11, 4, 25, + }; + + size_t i; + for( i = 0; i < ARRAYLENGTH(tp_table); ++i ) + { + uint8_t j = tp_table[i] - 1; + if( src->b[(j >> 3) + 0] & mask[j & 7] ) + tmp .b[(i >> 3) + 4] |= mask[i & 7]; + } + + *src = tmp; +} + + +/// Substitution boxes (S-boxes). +/// NOTE: This implementation was optimized to process two nibbles in one step (twice as fast). +static void SBOX(BIT64* src) +{ + BIT64 tmp = {0}; + + static const uint8_t s_table[4][64] = { + { + 0xef, 0x03, 0x41, 0xfd, 0xd8, 0x74, 0x1e, 0x47, 0x26, 0xef, 0xfb, 0x22, 0xb3, 0xd8, 0x84, 0x1e, + 0x39, 0xac, 0xa7, 0x60, 0x62, 0xc1, 0xcd, 0xba, 0x5c, 0x96, 0x90, 0x59, 0x05, 0x3b, 0x7a, 0x85, + 0x40, 0xfd, 0x1e, 0xc8, 0xe7, 0x8a, 0x8b, 0x21, 0xda, 0x43, 0x64, 0x9f, 0x2d, 0x14, 0xb1, 0x72, + 0xf5, 0x5b, 0xc8, 0xb6, 0x9c, 0x37, 0x76, 0xec, 0x39,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0xa8, 0xe2, 0x7d, + 0xa0, 0x9f, 0xf6, 0x5c, 0x6a, 0x09, 0x8d, 0xf0, 0x0f, 0xe3, 0x53, 0x25, 0x95, 0x36, 0x28, 0xcb, + } + }; + + size_t i; + for( i = 0; i < ARRAYLENGTH(s_table); ++i ) + { + tmp.b[i] = (s_table[i][src->b[i*2+0]] & 0xf0) + | (s_table[i][src->b[i*2+1]] & 0x0f); + } + + *src = tmp; +} + + +/// DES round function. +/// XORs src[0..3] with TP(SBOX(E(src[4..7]))). +static void RoundFunction(BIT64* src) +{ + BIT64 tmp = *src; + E(&tmp); + SBOX(&tmp); + TP(&tmp); + + src->b[0] ^= tmp.b[4]; + src->b[1] ^= tmp.b[5]; + src->b[2] ^= tmp.b[6]; + src->b[3] ^= tmp.b[7]; +} + + +void des_decrypt_block(BIT64* block) +{ + IP(block); + RoundFunction(block); + FP(block); +} + + +void des_decrypt(unsigned char* data, size_t size) +{ + BIT64* p = (BIT64*)data; + size_t i; + + for( i = 0; i*8 < size; i += 8 ) + des_decrypt_block(p); +} diff --git a/src/common/des.h b/src/common/des.h new file mode 100644 index 000000000..e42136436 --- /dev/null +++ b/src/common/des.h @@ -0,0 +1,15 @@ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder +#ifndef _DES_H_ +#define _DES_H_ + + +/// One 64-bit block. +typedef struct BIT64 { uint8_t b[8]; } BIT64; + + +void des_decrypt_block(BIT64* block); +void des_decrypt(unsigned char* data, size_t size); + + +#endif // _DES_H_ diff --git a/src/common/grfio.c b/src/common/grfio.c index 1d1ce756f..eefeb8296 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -2,8 +2,9 @@ // For more information, see LICENCE in the main folder #include "../common/cbasetypes.h" -#include "../common/showmsg.h" +#include "../common/des.h" #include "../common/malloc.h" +#include "../common/showmsg.h" #include "../common/strlib.h" #include "../common/utils.h" #include "grfio.h" @@ -57,63 +58,12 @@ char data_dir[1024] = ""; //---------------------------- int filelist_hash[256]; -//---------------------------- -// grf decode data table -//---------------------------- -static unsigned char BitMaskTable[8] = { - 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 -}; - -static char BitSwapTable1[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 -}; -static char BitSwapTable2[64] = { - 40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, - 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, - 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, - 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25 -}; -static char BitSwapTable3[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 -}; - -static unsigned char NibbleData[4][64]={ - { - 0xef, 0x03, 0x41, 0xfd, 0xd8, 0x74, 0x1e, 0x47, 0x26, 0xef, 0xfb, 0x22, 0xb3, 0xd8, 0x84, 0x1e, - 0x39, 0xac, 0xa7, 0x60, 0x62, 0xc1, 0xcd, 0xba, 0x5c, 0x96, 0x90, 0x59, 0x05, 0x3b, 0x7a, 0x85, - 0x40, 0xfd, 0x1e, 0xc8, 0xe7, 0x8a, 0x8b, 0x21, 0xda, 0x43, 0x64, 0x9f, 0x2d, 0x14, 0xb1, 0x72, - 0xf5, 0x5b, 0xc8, 0xb6, 0x9c, 0x37, 0x76, 0xec, 0x39, 0xa0, 0xa3, 0x05, 0x52, 0x6e, 0x0f, 0xd9,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c, 0x6a, 0x09, 0x8d, 0xf0, 0x0f, 0xe3, 0x53, 0x25, 0x95, 0x36, 0x28, 0xcb, - } -}; - // little endian char array to uint conversion static unsigned int getlong(unsigned char* p) { return (p[0] | p[1] << 0x08 | p[2] << 0x10 | p[3] << 0x18); } -/*========================================== - * Grf data decode : Subs - *------------------------------------------*/ static void NibbleSwap(unsigned char* Src, int len) { for(;0<len;len--,Src++) { @@ -121,94 +71,88 @@ static void NibbleSwap(unsigned char* Src, int len) } } -static void BitConvert(unsigned char* Src, char* BitSwapTable) + +/// Substitutes some specific values for others, leaves rest intact. Obfuscation. +/// NOTE: Operation is symmetric (calling it twice gives back the original input). +static uint8_t grf_substitution(uint8_t in) { - int lop,prm; - unsigned char tmp[8]; - memset(tmp,0,8); - for(lop=0;lop!=64;lop++) { - prm = BitSwapTable[lop]-1; - if (Src[(prm >> 3) & 7] & BitMaskTable[prm & 7]) { - tmp[(lop >> 3) & 7] |= BitMaskTable[lop & 7]; - } + uint8_t out; + + switch( in ) + { + case 0x00: out = 0x2B; break; + case 0x2B: out = 0x00; break; + case 0x6C: out = 0x80; break; + case 0x01: out = 0x68; break; + case 0x68: out = 0x01; break; + case 0x48: out = 0x77; break; + case 0x60: out = 0xFF; break; + case 0x77: out = 0x48; break; + case 0xB9: out = 0xC0; break; + case 0xC0: out = 0xB9; break; + case 0xFE: out = 0xEB; break; + case 0xEB: out = 0xFE; break; + case 0x80: out = 0x6C; break; + case 0xFF: out = 0x60; break; + default: out = in; break; } - memcpy(Src,tmp,8); + + return out; } -static void BitConvert4(unsigned char* Src) + +static void grf_shuffle_enc(BIT64* src) { - int lop,prm; - unsigned char tmp[8]; - tmp[0] = ((Src[7]<<5) | (Src[4]>>3)) & 0x3f; // ..0 vutsr - tmp[1] = ((Src[4]<<1) | (Src[5]>>7)) & 0x3f; // ..srqpo n - tmp[2] = ((Src[4]<<5) | (Src[5]>>3)) & 0x3f; // ..o nmlkj - tmp[3] = ((Src[5]<<1) | (Src[6]>>7)) & 0x3f; // ..kjihg f - tmp[4] = ((Src[5]<<5) | (Src[6]>>3)) & 0x3f; // ..g fedcb - tmp[5] = ((Src[6]<<1) | (Src[7]>>7)) & 0x3f; // ..cba98 7 - tmp[6] = ((Src[6]<<5) | (Src[7]>>3)) & 0x3f; // ..8 76543 - tmp[7] = ((Src[7]<<1) | (Src[4]>>7)) & 0x3f; // ..43210 v - - for(lop=0;lop!=4;lop++) { - tmp[lop] = (NibbleData[lop][tmp[lop*2]] & 0xf0) - | (NibbleData[lop][tmp[lop*2+1]] & 0x0f); - } + BIT64 out; + + out.b[0] = src->b[3]; + out.b[1] = src->b[4]; + out.b[2] = src->b[5]; + out.b[3] = src->b[0]; + out.b[4] = src->b[1]; + out.b[5] = src->b[6]; + out.b[6] = src->b[2]; + out.b[7] = grf_substitution(src->b[7]); + + *src = out; +} - memset(tmp+4,0,4); - for(lop=0;lop!=32;lop++) { - prm = BitSwapTable3[lop]-1; - if (tmp[prm >> 3] & BitMaskTable[prm & 7]) { - tmp[(lop >> 3) + 4] |= BitMaskTable[lop & 7]; - } - } - Src[0] ^= tmp[4]; - Src[1] ^= tmp[5]; - Src[2] ^= tmp[6]; - Src[3] ^= tmp[7]; + +static void grf_shuffle_dec(BIT64* src) +{ + BIT64 out; + + out.b[0] = src->b[3]; + out.b[1] = src->b[4]; + out.b[2] = src->b[6]; + out.b[3] = src->b[0]; + out.b[4] = src->b[1]; + out.b[5] = src->b[2]; + out.b[6] = src->b[5]; + out.b[7] = grf_substitution(src->b[7]); + + *src = out; } + static void decode_des_etc(unsigned char* buf, size_t len, int type, int cycle) { + BIT64* p = (BIT64*)buf; + size_t lop,cnt=0; if(cycle<3) cycle=3; else if(cycle<5) cycle++; else if(cycle<7) cycle+=9; else cycle+=15; - for(lop=0; lop*8<len; lop++, buf+=8) + for(lop=0; lop*8<len; lop++) { if(lop<20 || (type==0 && lop%cycle==0)) { // des - BitConvert(buf,BitSwapTable1); - BitConvert4(buf); - BitConvert(buf,BitSwapTable2); + des_decrypt_block(&p[lop]); } else { if(cnt==7 && type==0) { - unsigned char a; - unsigned char tmp[8]; - memcpy(tmp,buf,8); + grf_shuffle_dec(&p[lop]); cnt=0; - buf[0]=tmp[3]; - buf[1]=tmp[4]; - buf[2]=tmp[6]; - buf[3]=tmp[0]; - buf[4]=tmp[1]; - buf[5]=tmp[2]; - buf[6]=tmp[5]; - a=tmp[7]; - if(a==0x00) a=0x2b; - else if(a==0x2b) a=0x00; - else if(a==0x01) a=0x68; - else if(a==0x68) a=0x01; - else if(a==0x48) a=0x77; - else if(a==0x77) a=0x48; - else if(a==0x60) a=0xff; - else if(a==0xff) a=0x60; - else if(a==0x6c) a=0x80; - else if(a==0x80) a=0x6c; - else if(a==0xb9) a=0xc0; - else if(a==0xc0) a=0xb9; - else if(a==0xeb) a=0xfe; - else if(a==0xfe) a=0xeb; - buf[7]=a; } cnt++; } @@ -479,9 +423,7 @@ static char* decode_filename(unsigned char* buf, int len) int lop; for(lop=0;lop<len;lop+=8) { NibbleSwap(&buf[lop],8); - BitConvert(&buf[lop],BitSwapTable1); - BitConvert4(&buf[lop]); - BitConvert(&buf[lop],BitSwapTable2); + des_decrypt(&buf[lop],8); } return (char*)buf; } diff --git a/src/map/Makefile.in b/src/map/Makefile.in index 492300c3d..3f64942e0 100644 --- a/src/map/Makefile.in +++ b/src/map/Makefile.in @@ -4,13 +4,13 @@ COMMON_OBJ = ../common/obj_all/core.o ../common/obj_all/socket.o ../common/obj_a ../common/obj_all/nullpo.o ../common/obj_all/malloc.o ../common/obj_all/showmsg.o \ ../common/obj_all/utils.o ../common/obj_all/strlib.o ../common/obj_all/grfio.o \ ../common/obj_all/mapindex.o ../common/obj_all/ers.o ../common/obj_all/md5calc.o \ - ../common/obj_all/random.o + ../common/obj_all/random.o ../common/obj_all/des.o COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h \ ../common/db.h ../common/plugins.h ../common/lock.h \ ../common/nullpo.h ../common/malloc.h ../common/showmsg.h \ ../common/utils.h ../common/strlib.h ../common/grfio.h \ ../common/mapindex.h ../common/ers.h ../common/md5calc.h \ - ../common/random.h + ../common/random.h ../common/des.h COMMON_SQL_OBJ = ../common/obj_sql/sql.o COMMON_SQL_H = ../common/sql.h diff --git a/src/tool/CMakeLists.txt b/src/tool/CMakeLists.txt index 55ea2d267..afd066373 100644 --- a/src/tool/CMakeLists.txt +++ b/src/tool/CMakeLists.txt @@ -11,11 +11,13 @@ if( BUILD_MAPCACHE ) message( STATUS "Creating target mapcache" ) set( COMMON_HEADERS ${COMMON_MINI_HEADERS} + "${COMMON_SOURCE_DIR}/des.h" "${COMMON_SOURCE_DIR}/grfio.h" "${COMMON_SOURCE_DIR}/utils.h" ) set( COMMON_SOURCES ${COMMON_MINI_SOURCES} + "${COMMON_SOURCE_DIR}/des.c" "${COMMON_SOURCE_DIR}/grfio.c" "${COMMON_SOURCE_DIR}/utils.c" ) diff --git a/src/tool/Makefile.in b/src/tool/Makefile.in index 06813f843..a7f8afbf4 100644 --- a/src/tool/Makefile.in +++ b/src/tool/Makefile.in @@ -1,10 +1,10 @@ COMMON_OBJ = ../common/obj_all/minicore.o ../common/obj_all/malloc.o \ ../common/obj_all/showmsg.o ../common/obj_all/strlib.o \ - ../common/obj_all/utils.o ../common/obj_all/grfio.o + ../common/obj_all/utils.o ../common/obj_all/des.o ../common/obj_all/grfio.o COMMON_H = ../common/core.h ../common/mmo.h ../common/version.h \ ../common/malloc.h ../common/showmsg.h ../common/strlib.h \ - ../common/utils.h ../common/cbasetypes.h ../common/grfio.h + ../common/utils.h ../common/cbasetypes.h ../common/des.h ../common/grfio.h MAPCACHE_OBJ = obj_all/mapcache.o diff --git a/vcproj-10/map-server_sql.vcxproj.filters b/vcproj-10/map-server_sql.vcxproj.filters index 5351488d6..818de17b7 100644 --- a/vcproj-10/map-server_sql.vcxproj.filters +++ b/vcproj-10/map-server_sql.vcxproj.filters @@ -282,6 +282,9 @@ <ClInclude Include="..\src\common\db.h"> <Filter>common</Filter> </ClInclude> + <ClInclude Include="..\src\common\des.h"> + <Filter>common</Filter> + </ClInclude> <ClInclude Include="..\src\common\ers.h"> <Filter>common</Filter> </ClInclude> diff --git a/vcproj-10/map-server_txt.vcxproj.filters b/vcproj-10/map-server_txt.vcxproj.filters index bf2d728ae..a90302f0c 100644 --- a/vcproj-10/map-server_txt.vcxproj.filters +++ b/vcproj-10/map-server_txt.vcxproj.filters @@ -28,6 +28,9 @@ <ClCompile Include="..\src\common\db.c"> <Filter>common</Filter> </ClCompile> + <ClCompile Include="..\src\common\des.c"> + <Filter>common</Filter> + </ClCompile> <ClCompile Include="..\src\common\ers.c"> <Filter>common</Filter> </ClCompile> diff --git a/vcproj-9/map-server_sql.vcproj b/vcproj-9/map-server_sql.vcproj index d2c8192c2..d743bf0ed 100644 --- a/vcproj-9/map-server_sql.vcproj +++ b/vcproj-9/map-server_sql.vcproj @@ -236,6 +236,14 @@ > </File> <File + RelativePath="..\src\common\des.c" + > + </File> + <File + RelativePath="..\src\common\des.h" + > + </File> + <File RelativePath="..\src\common\ers.c" > </File> diff --git a/vcproj-9/map-server_txt.vcproj b/vcproj-9/map-server_txt.vcproj index 6291089a9..9e8abc1fd 100644 --- a/vcproj-9/map-server_txt.vcproj +++ b/vcproj-9/map-server_txt.vcproj @@ -531,6 +531,14 @@ > </File> <File + RelativePath="..\src\common\des.c" + > + </File> + <File + RelativePath="..\src\common\des.h" + > + </File> + <File RelativePath="..\src\common\ers.c" > </File> diff --git a/vcproj-9/mapcache.vcproj b/vcproj-9/mapcache.vcproj index 2fb78f198..94245c054 100644 --- a/vcproj-9/mapcache.vcproj +++ b/vcproj-9/mapcache.vcproj @@ -213,6 +213,14 @@ > </File> <File + RelativePath="..\src\common\des.c" + > + </File> + <File + RelativePath="..\src\common\des.h" + > + </File> + <File RelativePath="..\src\common\grfio.c" > </File> |