-
-
Save SoulGirlJP/18f53ea503ad54610a72400cf99a52e4 to your computer and use it in GitHub Desktop.
IDA Script for KMS (updated from Diamond25 Script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define RenameFunction(a, b) Message("Found %s at %a\r\n", b, a); MakeName(a, b) | |
#define START_ADDR 0x00400000 | |
static main() { | |
// Decodes/Encodes | |
FindCInPacketDecodeFunction("83 F8 01", "CInPacket::Decode1"); | |
FindCInPacketDecodeFunction("83 F8 02", "CInPacket::Decode2"); | |
FindCInPacketDecodeFunction("83 F8 04", "CInPacket::Decode4"); | |
FindCInPacketDecodeFunction("83 F8 08", "CInPacket::Decode8"); | |
//FindCInPacketDecodeFunction("2B 4E", "CInPacket::DecodeBuffer"); // Not done | |
FindCOutPacketEncodeFunction("3B CA 76", "COutPacket::Encode1"); | |
FindCOutPacketEncodeFunction("83 C1 02", "COutPacket::Encode2"); | |
FindCOutPacketEncodeFunction("83 C1 04", "COutPacket::Encode4"); | |
FindCOutPacketEncodeFunction("83 C1 08", "COutPacket::Encode8"); | |
//FindCOutPacketEncodeFunction("03 CB", "COutPacket::EncodeBuffer"); // Not Done | |
// CLogin::OnPacket | |
RenameFirstXrefFromCode(FindStringAndRenameFirstXrefFromData("GC:CreateMapleAccount", "CLogin::OnCreateMapleAccount"), "CLogin::OnPacket"); | |
RenameFirstXrefFromCode(FindStringAndRenameFirstXrefFromData("UI/Login.img/WorldSelect/BtChannel", "BTNChannel"), "CLogin::OnSelectChannelList"); | |
FindStringAndRenameFirstXrefFromData("GC:LoginGameServer", "CLogin::LoginStatus"); | |
// CField::OnPacket | |
RenameFirstXrefFromCode(FindStringAndRenameFirstXrefFromData("Effect/BasicEff.img/ObtacleAtomCreate/%", "CField::CreateObstacleAtom"), "CField::OnPacket"); | |
// CwvsContext::OnPacket | |
RenameFirstXrefFromCode(FindStringAndRenameFirstXrefFromData("[Memo_Load] [BlacklistNotLoading]", "CWvsContext::OnMemoResult"), "CwvsContext::OnPacket"); | |
FindStringAndRenameFirstXrefFromData("UI/UIWindow2.img/mapleMuseum", "CWvsContext::UI_OPEN" ); | |
// CUserPool::OnPacket | |
RenameFirstXrefFromCode(RenameFirstXrefFromCode(RenameFirstXrefFromCode(FindStringAndRenameFirstXrefFromData("UI/UIWindow.img/FloatNotice/%d/DrawOrigin/icon", "CUser::OnEffect"), "CUserLocal::OnAllCases"), "CUserLocal::OnPacket"), "CUserPool::OnPacket"); | |
// CSummonedPool::OnPacket | |
// Others | |
FindStringAndRenameFirstXrefFromData("UI/UIWindow2.img/Reset/AP/stat%d/%d", "GetStatCanvas"); | |
FindAoBAndRename("6A 0D 50 8B CF E8 ? ? ? FF 8B CF 85 DB 74 1C", "GW_CharacterStat::Decode"); | |
FindStringAndRenameFirstXrefFromData("%d (MAX)", "CUIToolTip::SetToolTip_Equip"); | |
FindStringAndRenameFirstXrefFromData("jobCategory", "Field::JobCategoryCond::Parse"); | |
FindStringAndRenameFirstXrefFromData("battleFieldTeam", "Field::BattlefieldTeamCond::Parse"); | |
FindStringAndRenameFirstXrefFromData("itemLEV", "CUIToolTip::CUIToolTip"); | |
FindStringAndRenameFirstXrefFromData("HACK", "CWvsContext::OnFakeGMNotice"); | |
FindStringAndRenameFirstXrefFromData("Unknown error 0x%0lX", "com_error::ErrorMessage"); | |
FindStringAndRenameFirstXrefFromData("Invalid Decoding\r\n", "CInPacket::WriteClientLog"); | |
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ | |
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ | |
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ | |
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ | |
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ | |
} | |
static FindNextCommand(pCommandHex, pFrom) { | |
return FindBinary(pFrom, SEARCH_DOWN, pCommandHex); | |
} | |
static GetCallAddress(pFrom) { | |
auto addr = FindNextCommand("E8", pFrom); | |
if (addr == BADADDR) return BADADDR; | |
Message(" %a\r\n", addr); | |
return pFrom + Dword(addr + 1); | |
} | |
static FindFirstText(pWhat, pMin) { | |
auto result = FindText(pMin, SEARCH_DOWN, 0, 0, pWhat); | |
if (result == BADADDR) | |
return BADADDR; | |
return Rfirst(result); | |
} | |
static FindAoBAndRename(AoB, name) { | |
auto addr = FindBinary(START_ADDR, SEARCH_DOWN, AoB); | |
if (addr == BADADDR) | |
return BADADDR; | |
auto functionBase = GetFunctionAttr(addr, FUNCATTR_START); | |
RenameFunction(functionBase, name); | |
return functionBase; | |
} | |
static FindStringAndRenameFirstXrefFromData(text, name) { | |
return FindStringAndRenameXrefSteps(text, name, 1); | |
} | |
static FindString(addr, text) { | |
return FindBinary(addr, SEARCH_DOWN, sprintf("\"%s\"", text)); | |
} | |
static FindStringAndRenameXrefSteps(text, name, steps) { | |
auto addr = FindString(START_ADDR, text); | |
if (addr == BADADDR) | |
return BADADDR; | |
addr = DfirstB(addr); | |
if (addr == BADADDR) { | |
return BADADDR; | |
} | |
auto i; | |
for (i = 1; i < steps; i++) { | |
addr = GetFunctionAttr(addr, FUNCATTR_START); | |
auto callingFunction = RfirstB(addr); // Get xref to function | |
if (callingFunction == BADADDR) | |
return BADADDR; | |
addr = callingFunction; | |
} | |
addr = GetFunctionAttr(addr, FUNCATTR_START); | |
if (addr != BADADDR) { | |
RenameFunction(addr, name); | |
} | |
return addr; | |
} | |
static RenameFirstXrefFromData(address, name) { | |
auto callingFunction = DfirstB(address); | |
if (callingFunction == BADADDR) | |
return BADADDR; | |
auto functionBase = GetFunctionAttr(callingFunction, FUNCATTR_START); | |
RenameFunction(functionBase, name); | |
return functionBase; | |
} | |
static RenameFirstXrefFromCode(address, name) { | |
auto callingFunction = RfirstB(address); | |
if (callingFunction == BADADDR) | |
return BADADDR; | |
auto functionBase = GetFunctionAttr(callingFunction, FUNCATTR_START); | |
RenameFunction(functionBase, name); | |
return functionBase; | |
} | |
static FindCInPacketDecodeFunction(identifier, name) { | |
auto lastResult = 0x00400000; | |
while (1) { | |
lastResult = FindBinary(lastResult, SEARCH_DOWN, "02 8D 45 D8 C7 45 D8 26 00 00 00"); | |
if (lastResult == BADADDR) | |
return; | |
auto tmp = FindBinary(lastResult, 0x00, identifier); | |
if (tmp != BADADDR && lastResult - tmp < 0x15) { | |
auto functionBase = GetFunctionAttr(lastResult, FUNCATTR_START); | |
Message("Found %s at %a\r\n", name, functionBase); | |
RenameFunction(functionBase, name); | |
return; | |
} | |
lastResult = lastResult + 0x50; | |
} | |
} | |
static FindCOutPacketEncodeFunction(identifier, name) { | |
auto lastResult = 0x00400000; | |
while (1) { | |
lastResult = FindBinary(lastResult, SEARCH_DOWN, "04 85 D2 74 03 8B 52 FC 8B 4E 08"); | |
if (lastResult == BADADDR) | |
return; | |
auto tmp = FindBinary(lastResult, SEARCH_DOWN, identifier); | |
if (tmp != BADADDR && tmp - lastResult < 0x15) { | |
auto functionBase = GetFunctionAttr(lastResult, FUNCATTR_START); | |
Message("Found %s at %a\r\n", name, functionBase); | |
RenameFunction(functionBase, name); | |
return; | |
} | |
lastResult = lastResult + 0x50; | |
} | |
} | |
static FindFunctionsByAoB(AoB, Names, Amount) { | |
auto lastResult = 0x00400000; | |
auto lastFunctionResult = -1; | |
auto i = 0; | |
for (i; i < Amount; i = i) { | |
lastResult = FindBinary(lastResult, SEARCH_DOWN, AoB); | |
if (lastResult == BADADDR) | |
return; | |
auto functionBase = GetFunctionAttr(lastResult, FUNCATTR_START); | |
if (functionBase != lastFunctionResult) { | |
Message("Found %s at %a\r\n", Names[i], functionBase); | |
RenameFunction(functionBase, Names[i]); | |
lastResult = functionBase; | |
lastFunctionResult = functionBase; | |
i++; | |
} | |
lastResult = lastResult + 0x50; | |
} | |
} | |
static NameNthCall(address, callNr, name) { | |
if (address == BADADDR) | |
return BADADDR; | |
auto i = 1; | |
while (1) { | |
auto addr = FindNextCommand("E8", address); | |
if (addr == BADADDR) return BADADDR; | |
Message("Command at %a\r\n", addr); | |
auto instruction = DecodeInstruction(addr); | |
if (instruction.itype != 16) continue; | |
auto funcAddr = instruction.Op0.addr; | |
auto funcName = GetFunctionName(funcAddr); | |
Message("Found %s at %a ? %d\r\n", funcName, funcAddr, i); | |
if (funcName != "") { | |
if (i == callNr) { | |
RenameFunction(funcAddr, name); | |
Message("Found %s at %a\r\n", name, funcAddr); | |
break; | |
} | |
else { | |
i++; | |
} | |
} | |
address = addr + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment