Updated gdc-psyfork with current (NPOTB).

- Added support for custom symbols.txt path (-s <path>).
- Added support for dlsym symbol lookup in linux bins (-n).
- Updated gdc_core.sh example script to account for new options above.
- Updated symbols.txt.
This commit is contained in:
Nicholas Hastings 2013-01-07 09:09:14 -05:00
parent a66adcbc88
commit f757d5f09b
3 changed files with 110 additions and 22 deletions

View File

@ -8,6 +8,9 @@ ENGINE_BIN=${ENGINE_PATH}/bin/engine
GAME_BIN=${ENGINE_PATH}/${GAME_DIR}/bin/server
STEAMINF=${ENGINE_PATH}/${GAME_DIR}/steam.inf
GDC_PATH=${SM_PATH}/tools/gdc-psyfork
GDC_BIN=${GDC_PATH}/Release/gdc
if [ "${GAMEDATA_DIR}" == "" ] ; then
GAMEDATA_DIR=${GAME_DIR}
fi
@ -107,16 +110,34 @@ cd ${SM_PATH}/tools/gdc-psyfork
hg pull -u
echo -e "\n"
cd ${ENGINE_PATH}
for i in "${gamedata_files[@]}"
do
./Release/gdc \
-g ${GAME_DIR} \
NO_SYMTABLE=
readelf --sections ${GAME_BIN}${BIN_EXT}.so | grep --quiet .symtab
if [ "${PIPESTATUS[1]}" != "0" ] ; then
NO_SYMTABLE=" -n"
fi
readelf --sections ${GAME_BIN}${BIN_EXT}.so | grep --quiet .strtab
if [ "${PIPESTATUS[1]}" != "0" ] ; then
NO_SYMTABLE=" -n"
fi
# having an issue upon exit after loading some source2007 server bins, invalid free in sendtable dtor, idk. suppress.
MALLOC_CHECK_=0 ${GDC_BIN} \
-g ${GAMEDATA_DIR} \
-e ${ENGINE_NAME} \
-f ${SM_PATH}/gamedata/$i \
-b ${GAME_BIN}${BIN_EXT}.so \
-x ${ENGINE_BIN}${BIN_EXT}.so \
-w ${GAME_BIN}.dll \
-y ${ENGINE_BIN}.dll
-y ${ENGINE_BIN}.dll \
-s ${GDC_PATH}/symbols.txt \
${NO_SYMTABLE}
echo -e "------------------------------------------------------\n"
done

View File

@ -16,12 +16,23 @@ char *game_binary = NULL;
char *engine_binary = NULL;
char *wgame_binary = NULL;
char *wengine_binary = NULL;
char *symbols_file = NULL;
bool use_symtab = true;
inline bool IsDigit( char c )
{
return c < 58 && c > 47;
}
void PrintUsage()
{
printf("Usage: ./gdc -g <game> -e <engine name> -f <gamedata file> -b <game binary> -x <engine binary> -w <win game binary> -y <win engine binary> [-s <symbols.txt file>]\n");
printf("Other options:\n");
printf(" -d\tAdd debug output\n");
printf(" -n\tDon't use symbol table for lookups (falls back to dlsym)\n");
}
int main(int argc, char **argv)
{
char *gamedata = NULL;
@ -29,12 +40,18 @@ int main(int argc, char **argv)
opterr = 0;
int opt;
while ((opt = getopt(argc, argv, "b:de:f:g:x:w:y:")) != -1)
while ((opt = getopt(argc, argv, "b:nde:f:g:x:w:y:s:")) != -1)
{
switch (opt)
{
case 'd':
debug = true;
break;
case 'n':
use_symtab = false;
break;
case 'g':
game = optarg;
break;
@ -63,18 +80,23 @@ int main(int argc, char **argv)
wengine_binary = optarg;
break;
case 's':
symbols_file = optarg;
break;
case '?':
printf("Usage: ./gdc -g <game> -e <engine name> -f <gamedata file> -b <game binary> -x <engine binary> -w <win game binary> -y <win engine binary>\n");
PrintUsage();
return 0;
default:
printf("WHAT\n");
return 0;
}
}
if (!game || !engine || !gamedata || !game_binary || !engine_binary || !wgame_binary || !wengine_binary)
{
printf("Usage: ./gdc -g <game> -e <engine name> -f <gamedata file> -b <game binary> -x <engine binary> -w <win game binary> -y <win engine binary>\n");
PrintUsage();
return 0;
}
@ -125,7 +147,7 @@ int main(int argc, char **argv)
}
CGameConfig symbols;
if (!symbols.EnterFile("symbols.txt", err, sizeof(err)))
if (!symbols.EnterFile(symbols_file ? symbols_file : "symbols.txt", err, sizeof(err)))
{
printf("symbols.txt: %s\n", err);
return 0;
@ -178,7 +200,16 @@ int main(int argc, char **argv)
int newOffset;
if (symvt[0])
{
void **newvt = (void**) mu.ResolveSymbol(ghandle, symvt);
void **newvt = NULL;
if( use_symtab )
{
newvt = (void**)mu.ResolveSymbol(ghandle, symvt);
}
else
{
newvt = (void **)dlsym(ghandle, symvt);
}
if (!newvt)
{
printf("? O: %-22s - can't find, skipping\n", symvt);
@ -362,13 +393,15 @@ int checkSigStringW(int file, const char* symbol)
int checkSigStringL(void *handle, const char* symbol)
{
bool isAt = (symbol[0] == '@');
bool isAt = (symbol[0] == '@' && symbol[1] != '\0');
int matches = 0;
bool dummy;
if (isAt)
{
if( mu.ResolveSymbol(handle, symbol + 1) )
if( use_symtab && mu.ResolveSymbol(handle, &symbol[1]) )
matches = 1;
else if( !use_symtab && dlsym(handle, &symbol[1]) )
matches = 1;
}
else
@ -403,15 +436,30 @@ void findFuncPos(const char *sym, int &func, int &params)
int findVFunc(void *handle, void **vt, const char *symbol)
{
int offset = 1;
if( !use_symtab )
{
for (int i = 0; i < 1000; i++ )
{
void *pFunc = vt[i];
if( !pFunc )
continue;
if( pFunc == dlsym(handle, symbol ) )
return i - 2;
}
return -1;
}
int funcPos, paramPos;
findFuncPos(symbol, funcPos, paramPos);
for (int i = 0; i < 1000; i++)
{
void *pFunc = vt[i];
if( !pFunc )
continue;
const char *s;
if (!(s = mu.ResolveAddr(handle, pFunc)))
@ -426,12 +474,11 @@ int findVFunc(void *handle, void **vt, const char *symbol)
if (strcmp(s + tempFuncPos, symbol + funcPos) == 0)
{
offset = i;
break;
return i - 2;
}
}
return offset - 2;
return -1;
}
unsigned int strncopy(char *dest, const char *src, size_t count)

View File

@ -76,6 +76,7 @@
"ShouldGib" "_ZN9CTFPlayer9ShouldGibERK15CTakeDamageInfob"
"GetRadius" "_ZN13CTFBaseRocket9GetRadiusEv"
"DeflectPlayer" "_ZN13CTFWeaponBase13DeflectPlayerEP9CTFPlayerS1_R6VectorS3_S3_"
"GetDataDescMap" "_ZN11CBaseEntity14GetDataDescMapEv"
// CSSDM
"IPointsForKill" "_ZN14CTeamplayRules14IPointsForKillEP11CBasePlayerS1_"
@ -84,6 +85,12 @@
// NapalmLagFix
"RadiusDamage" "_ZN10CGameRules12RadiusDamageERK15CTakeDamageInfoRK6VectorfiP11CBaseEntity"
// V
"CTFFlameThrower::FireProjectile" "_ZN16CTFWeaponBaseGun14FireProjectileEP9CTFPlayer"
"CTFFlameThrower::FireFlameRocket" "_ZN16CTFWeaponBaseGun15FireFlameRocketEP9CTFPlayer"
"CTFPlayer::GetMaxHealth" "_ZNK11CBaseEntity12GetMaxHealthEv"
"CBaseEntity::GetBaseEntity" "_ZN11CBaseEntity13GetBaseEntityEv"
}
"Options"
@ -180,4 +187,17 @@
"GiveNamedItem" "_ZN11CBasePlayer13GiveNamedItemEPKcib"
}
}
"#default"
{
"#supported"
{
"game" "synergy"
}
"Keys"
{
"GiveNamedItem" "_ZN11CBasePlayer13GiveNamedItemEPKcib"
}
}
}