Skip to content

Instantly share code, notes, and snippets.

@diamondo25
Created July 30, 2015 12:02
Show Gist options
  • Save diamondo25/be95345a2875ab4342cd to your computer and use it in GitHub Desktop.
Save diamondo25/be95345a2875ab4342cd to your computer and use it in GitHub Desktop.
MapleStory IDC script
// IDC script for identifying functions and such
#include <idc.idc>
#define RenameFunction(a, b) Message("Found %s at %a\r\n", b, a); MakeName(a, b)
#define START_ADDR 0x00400000
static main() {
auto addr = BADADDR;
auto onMovePacket = FindAoBAndRename("25 0C FE FF FF 05 E8 03", "?OnMovePacket@CMovePath@@QAEXAAVCInPacket@@H@Z");
NameNthCall(onMovePacket, 3, "?Decode@CMovePath@@QAEXAAVCInPacket@@H@Z");
FindStringAndRenameFirstXrefFromData("Delivered", "?Decode@CharacterData@@QAE_KAAVCInPacket@@H@Z");
FindStringAndRenameFirstXrefFromData("CharacterName(%s), WorldID(%d), Ch(%d)", "CWvsApp::ZtlExceptionHandler");
FindStringAndRenameFirstXrefFromData("Unknown error 0x%0lX", "com_error::ErrorMessage");
FindStringAndRenameFirstXrefFromData("%d (MAX)", "CUIToolTip::SetToolTip_Equip");
FindStringAndRenameFirstXrefFromData("GM can not transfer worlds.", "CCashShop::CheckTransferWorldPossible");
FindStringAndRenameFirstXrefFromData("Please visit the website to charge your account.", "CCashShop::OnStatusCharge");
FindStringAndRenameFirstXrefFromData("SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "?Init@CSystemInfo@@QAEXXZ");
FindStringAndRenameFirstXrefFromData("DBGHELP.DLL", "ZExceptionHandler::InitDbgHelpFunctions");
FindStringAndRenameFirstXrefFromData("battleFieldTeam", "Field::BattlefieldTeamCond::Parse");
FindStringAndRenameFirstXrefFromData("jobCategory", "Field::JobCategoryCond::Parse");
FindStringAndRenameFirstXrefFromData("http://maplestory.nexon.net", "CClientSocket::GetGuestIDRegistrationURL");
FindStringAndRenameFirstXrefFromData("SeDebugPrivilege", "GetSEPrivilege");
FindStringAndRenameFirstXrefFromData("Congrats! You have gained upgrade potion by playing an hour!", "CFloatNotice::CreateEffEvolRing");
FindStringAndRenameFirstXrefFromData("Etc/SetItemInfo.img", "CItemInfo::RegisterSetItemInfo");
FindStringAndRenameFirstXrefFromData("Can be equipped on #cone-handed sword or two-handed sword.#", "CItemInfo::GetItemDesc");
FindStringAndRenameFirstXrefFromData("epicItem", "CItemInfo::RegisterEquipItemInfo");
FindStringAndRenameFirstXrefFromData("%02X%02X%02X%02X%02X%02X_%02X%02X%02X%02X", "CItemInfo::RegisterEquipItemInfo");
FindStringAndRenameFirstXrefFromData("Please select the World you would like to play in.", "CUIWorldSelect::MakeAdvice");
FindStringAndRenameFirstXrefFromData("Play!", "StartUpWndProc");
FindStringAndRenameFirstXrefFromData("%d/%02d/%02d %02d:%02d", "CUIGuildBBS::FormatDate");
FindStringAndRenameFirstXrefFromData("QuestID : %d", "CUIQuestInfo::LoadData");
FindStringAndRenameFirstXrefFromData("UI/UIWindow2.img/Reset/AP/stat%d/%d", "GetStatCanvas");
FindStringAndRenameFirstXrefFromData("[W:%2d]", "CUIStatusBar::ChatLogDraw");
FindStringAndRenameFirstXrefFromData("itemLEV", "CUIToolTip::CUIToolTip");
FindStringAndRenameFirstXrefFromData("act2", "?OnChat@CUser@@QAEXAAVCInPacket@@@Z");
FindStringAndRenameFirstXrefFromData("criticaldamageMin", "CUserLocal::SetPassiveSkillDataForced");
FindStringAndRenameFirstXrefFromData("Map/MapHelper.img/weather/squib/squib%d", "CUserPreview::ShowFireCrack");
FindStringAndRenameFirstXrefFromData("R6025 %d %d %d %d", "CVecCtrlMob::CtrlUpdateActiveMove");
FindStringAndRenameFirstXrefFromData("Something went wrong !!!!!", "CWvsContext::ShowNewYearCard");
FindStringAndRenameFirstXrefFromData("Are you sure you want to use it?", "CWvsContext::SendConsumeCashItemUseRequest");
FindStringAndRenameFirstXrefFromData("HACK", "CWvsContext::OnFakeGMNotice");
FindStringAndRenameFirstXrefFromData("SOFTWARE\\NEXON\\eTracer\\", "?Start_eTracer@@YAXKK@Z");
FindStringAndRenameFirstXrefFromData("Invalid Decoding\r\n", "?WriteClientLog@CInPacket@@IAEXXZ");
FindStringAndRenameFirstXrefFromData("%s\\%s_%04d%02d%02d_%02d%02d%02d.jpg", "?SaveAntiMacroScreenShot@CWvsContext@@QAEXV?$ZXString@D@@@Z");
//FindStringAndRenameFirstXrefFromData("UI/UIWindow2.img/PersonalShop/main/backgrnd", "??0CPersonalShopDlg@@QAE@XZ");
// Hackshield related stuff
FindStringAndRenameFirstXrefFromData("%s\HShield", "SendHSLog");
FindStringAndRenameFirstXrefFromData("HSUpChk.log", "?LibChk_SetLog@@YGKPBD@Z");
FindStringAndRenameFirstXrefFromData("_AHNPRODUCTID=", "?GetHSEnvInfo@@YGKPBDPAU_HSUPDATEENV@@@Z");
FindStringAndRenameFirstXrefFromData("z`La4~`8D2A64lA[1#HaD$y84(I.", "?InitWiniNet@CHsMonitor@@AAEKXZ");
FindStringAndRenameFirstXrefFromData("<[H8@_A8@_`+c:L{t:%{z(L8c`:{@lHaA2^vd2D~D_5$D^Lad<E[@<A84[S$1#:.", "?SendErrorbyHttp@CHsMonitor@@QAEKKPBD@Z");
FindStringAndRenameFirstXrefFromData("<[H8@_A8@_`+c:L{t:%{z(L8c`:{@lHaA2^vd2D~D_5$D^Lad<E[@<A84[S$1#:.", "?SendErrorbyHttp@CHsMonitor@@QAEKKPBD@Z");
// CRC stuff
addr = FindBinary(START_ADDR, SEARCH_DOWN, "00 00 00 00 B7 1D C1 04 6E 3B 82 09 D9 26 43 0D");
if (addr != BADADDR) {
RenameFunction(addr, "?ms_adwCrc32Table@CCrc32@@0PAKA");
RenameFirstXrefFromData(addr, "?GetCrc32@CCrc32@@SAKPBEKKHPAKH@Z");
}
FindCInPacketDecodeFunction("83 F8 01", "?Decode1@CInPacket@@QAEEXZ");
FindCInPacketDecodeFunction("83 F8 02", "?Decode2@CInPacket@@QAEEXZ");
FindCInPacketDecodeFunction("83 F8 04", "?Decode4@CInPacket@@QAEEXZ");
FindCInPacketDecodeFunction("83 F8 08", "?Decode8@CInPacket@@QAEEXZ");
FindCInPacketDecodeFunction("3B C7", "?DecodeBuffer@CInPacket@@QAEEXZ");
FindCOutPacketEncodeFunction("41 3B C8", "?Encode1@COutPacket@@QAEEXZ");
FindCOutPacketEncodeFunction("83 C1 02", "?Encode2@COutPacket@@QAEEXZ");
FindCOutPacketEncodeFunction("83 C1 04", "?Encode4@COutPacket@@QAEEXZ");
FindCOutPacketEncodeFunction("83 C1 08", "?Encode8@COutPacket@@QAEEXZ");
FindCOutPacketEncodeFunction("03 CB", "?EncodeBuffer@COutPacket@@QAEEXZ");
FindAoBAndRename("83 FA 02 73 17 68", "CIOBufferManipulator::DecodeStr");
FindAoBAndRename("6A 0D 50 8B CF E8 ? ? ? FF 8B CF 85 DB 74 1C", "GW_CharacterStat::Decode");
FindAoBAndRename("81 FB B4 05 00 00", "?DecryptData@CInPacket@@QAEXK@Z");
FindAoBAndRename("81 FF B4 05 00 00", "COutPacket::MakeBufferList");
auto names = object();
names[0] = "?RawDecode@GW_ItemSlotPet@@MAEXAAVCInPacket@@@Z";
names[1] = "?RawDecode@GW_ItemSlotEquip@@MAEXAAVCInPacket@@@Z";
names[2] = "?Decode@GW_CharacterStat@@QAEXAAVCInPacket@@H@Z";
//FindFunctionsByAoB("0F B7 C8 8D 56 ? E8 ? ? ? FF 8B CF 89 46 ?", names, 3);
names = object();
names[0] = "?YesNo2@CLoginUtilDlg@@SAHJ@Z";
names[1] = "?YesNo3@CLoginUtilDlg@@SAHJ@Z";
names[2] = "?Notice@CLoginUtilDlg@@SAXJPAV?$ZRef@VCDialog@@@@@Z";
names[3] = "?Error@CLoginUtilDlg@@SAXJPAV?$ZRef@VCDialog@@@@@Z";
FindFunctionsByAoB("6A 01 6A 0A 50 68 8E 00 00 00 68 F9 00 00 00", names, 4);
addr = FindBinary(START_ADDR, SEARCH_DOWN, "6A 01 6A 0A 50 68 8E 00 00 00 68 F9 00 00 00");
if (addr != BADADDR) {
addr = GetCallAddress(addr);
RenameFunction(addr, "?CreateFadeWnd@CFadeWnd@@QAEXJJPBGJHPAXHW4UIOrigin@CWnd@@@Z");
}
addr = FindAoBAndRename("68 FF FF FF 7F 8B CE C7 44 24 1C 00 00 00 00 E8 ? ? FF FF", "COutPacket::COutPacket");
if (addr != BADADDR) {
// Quickly refind
addr = FindBinary(addr, SEARCH_DOWN, "68 FF FF FF 7F 8B CE C7 44 24 1C 00 00 00 00 E8 ? ? FF FF");
Message(" %a\r\n", addr);
addr = GetCallAddress(addr); // address of COutPacket::Init_1
Message(" %a\r\n", addr);
//RenameFunction(addr, "COutPacket::Init_1");
addr = GetCallAddress(addr); // First call = COutPacket__Init
Message(" %a\r\n", addr);
//RenameFunction(addr, "COutPacket::Init");
/*
auto initByte = FindBinary(addr, SEARCH_DOWN, "E8");
auto encode2 = FindBinary(initByte + 2, SEARCH_DOWN | SEARCH_NEXT, "E8");
if (initByte != BADADDR) RenameFunction(initByte, "COutPacket::InitByte");
if (encode2 != BADADDR) RenameFunction(initByte, "COutPacket::Encode2");
*/
}
FindAoBAndRename("68 FF FF FF 7F 8B CE C7 44 24 1C 00 00 00 00 E8 ? ? FF FF", "COutPacket::COutPacket");
FindAoBAndRename("6A 0D 50 8B CF E8 ? ? ? ?", "?Decode@GW_CharacterStat@@QAEXAAVCInPacket@@H@Z");
FindAoBAndRename("6A 02 53 55 E8 ? ? ? ?", "?Decode@AvatarLook@@QAEXAAVCInPacket@@@Z");
FindAoBAndRename("3D 33 27 00 00 74 08 50 8B ? E8", "?Flush@CClientSocket@@QAEXXZ");
FindAoBAndRename("? 00 FF FF 1F", "?Random@CRand32@@QAEIXZ");
// Packet handlers
FindAoBAndRename("68 0A 00 00 22", "?OnCheckCrcResult@CClientSocket@@IAEXAAVCInPacket@@@Z");
addr = FindAoBAndRename("68 04 00 00 21", "?OnAuthenCodeChanged@CClientSocket@@IAEXAAVCInPacket@@@Z");
RenameFirstXrefFromCode(addr, "?ProcessPacket@CClientSocket@@IAEXAAVCInPacket@@@Z");
FindAoBAndRename("68 04 00 00 21", "?OnAuthenCodeChanged@CClientSocket@@IAEXAAVCInPacket@@@Z");
RenameFirstXrefFromCode(FindStringAndRenameFirstXrefFromData("\\ It may be wating long time", "CField::OnShowQuestLoadingPacket"), "CField::OnPacket");
// Some WvsContext thingies
names = object();
names[0] = "?OnMigrateCommand@CClientSocket@@IAEXAAVCInPacket@@@Z";
names[1] = "?OnError@CClientSocket@@QAEXH@Z";
names[2] = "?OnClose@CClientSocket@@QAEXXZ";
FindFunctionsByAoB("68 02 00 00 21", names, 3); // push 0x21000002u
}
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, "8D 45 EC 50 C7 45 EC 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, "8B F1 8B 46 04 57 8D 7E 04");
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