---
Improvized upon rolle3k's script to define the sub-functions as well.
Works fine with 1.2.0, and won't rename already defined functions. Could be more optimal but who cares, right?
#include <idc.idc>
static main( )
{
auto dwGalaxyTable, dwIndex, dwFunction, sName;
Message( "Galaxy.IDC by rolle3k~ and friends\r\n" );
dwGalaxyTable = FindBinary( INF_BASEADDR, SEARCH_DOWN, "56 57 33 FF BE ? ? ? ?" );
if ( dwGalaxyTable == BADADDR ) {
Message( "GALAXY: Couldn't locate table\r\n" );
return;
}
dwGalaxyTable = Dword( dwGalaxyTable + 5 );
Message( "GALAXY: Found table @ 0x%08X\r\n", dwGalaxyTable );
for( dwIndex = 0; getGalaxyFunction( dwGalaxyTable, dwIndex ) != -1; dwIndex++ )
{
dwFunction = getGalaxyFunction( dwGalaxyTable, dwIndex );
sName = getGalaxyName( dwGalaxyTable, dwIndex );
processGalaxyFunction( dwFunction, sName );
}
Message( "GALAXY: Done!\r\n" );
}
static getGalaxyFunction( dwTable, dwIndex )
{
return Dword( dwTable + ( dwIndex * 0x18 ) );
}
static getGalaxyName( dwTable, dwIndex )
{
return GetString( Dword( dwTable + ( dwIndex * 0x18 ) + 4 ), -1, ASCSTR_C );
}
static processGalaxyFunction( dwFunction, sName )
{
auto sCall, dwCall, dwEnd, sInstruction;
dwEnd = FindFuncEnd( dwFunction );
Message( "GALAXY: Processing 0x%08X -> %s\r\n", dwFunction, sName );
if ( dwFunction == BADADDR || dwEnd == BADADDR ) {
Message( "-> Bailing out: Bad start or end address\r\n" );
return;
}
MakeName( dwFunction, "Galaxy_" + sName );
while ( 1 ) {
sInstruction = GetMnem( dwFunction );
if ( sInstruction == "call" || sInstruction == "jmp" ) {
if ( GetOpType( dwFunction, 0 ) > 1 && GetOpType( dwFunction, 0 ) < 8 ) {
sCall = GetOpnd( dwFunction, 0 );
if ( substr( sCall, 0, 4 ) != "sub_" && substr( sCall, 0, 4 ) != "loc_" ) {
Message( "-> Subcall already has a name (%s)\r\n", sCall );
return;
}
sCall = substr( sCall, 4, strlen( sCall ) );
dwCall = xtol( sCall );
if ( dwCall > 0 && dwCall != 0xFFFFFFFF ) {
Message( "-> Found subcall: 0x%08X -> %s\r\n", dwCall, "impl" + sName );
MakeName( dwCall, "impl" + sName );
}
}
return;
}
dwFunction = NextHead( dwFunction, dwEnd );
if ( dwFunction == BADADDR || dwFunction > dwEnd ) {
Message( "-> Couldn't locate subcall\r\n" );
return;
}
}
}