Skip to content
This repository has been archived by the owner on Aug 26, 2020. It is now read-only.

Commit

Permalink
修复内存问题并将插件双语化
Browse files Browse the repository at this point in the history
  • Loading branch information
torusrxxx authored Nov 15, 2016
1 parent 76800a6 commit 4bfb7ca
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions pluginmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "pluginsdk\_plugins.h"
#include "pluginsdk\_exports.h" // modified _exports.h to use _dbg_addrinfoget export
#include "pluginsdk\bridgemain.h"
#include "utf8\utf8.h"
#include "resource.h"
#ifdef _WIN64
#pragma comment(lib, "pluginsdk\\x64dbg.lib")
#pragma comment(lib, "pluginsdk\\x64bridge.lib")
Expand All @@ -14,11 +16,29 @@
#define DLL_EXPORT extern "C" __declspec(dllexport)
#endif //DLL_EXPORT

#define plugin_name "ExtraInfo"
#define plugin_version 1

int pluginHandle;
HWND hwndDlg;
HINSTANCE hModule;

std::string LoadUTF8String(int index)
{
wchar_t p[512];
int len;
memset(p, 0, sizeof(p));
if((len = LoadString(hModule, index, (LPWSTR)p, 512)) == 0)
{
return "";
}
else
{
std::wstring utf16line(p, len);
std::string utf8line;
utf8::utf16to8(utf16line.begin(), utf16line.end(), std::back_inserter(utf8line));
return utf8line;
}
}

int compareFunc(const void* a, const void* b)
{
Expand All @@ -43,28 +63,28 @@ void cbPlugin(CBTYPE cbType, LPVOID generic_param)
if(param->hWindow == GUI_DISASSEMBLY)
{
XREF_INFO info;
info.refcount = 0;
info.references = nullptr;
if(DbgXrefGet(param->VA, &info) && info.refcount > 0)
{
std::string output;
std::qsort(info.references, info.refcount, sizeof(info.references[0]), &compareFunc);
int t = -1;
int i;
int t = XREF_NONE;
duint i;
for(i = 0; i < info.refcount && i < 10; i++)
{
if(t != info.references[i].type)
{
if(t != -1)
output += ",";
switch(info.references[i].type)
{
case XREF_JMP:
output += "Jump from ";
output += LoadUTF8String(IDS_JMPFROM);
break;
case XREF_CALL:
output += "Call from ";
output += LoadUTF8String(IDS_CALLFROM);
break;
default:
output += "Reference from ";
output += LoadUTF8String(IDS_REFFROM);
break;
}
t = info.references[i].type;
Expand All @@ -85,7 +105,8 @@ void cbPlugin(CBTYPE cbType, LPVOID generic_param)
if(info.refcount > 10)
output += " ...";
GuiAddInfoLine(output.c_str());
BridgeFree(info.references);
if(info.references)
BridgeFree(info.references);
}
}
}
Expand All @@ -94,7 +115,7 @@ DLL_EXPORT bool pluginit(PLUG_INITSTRUCT* initStruct)
{
initStruct->pluginVersion = plugin_version;
initStruct->sdkVersion = PLUG_SDKVERSION;
strcpy(initStruct->pluginName, plugin_name);
strcpy_s(initStruct->pluginName, LoadUTF8String(IDS_PLUGINAME).c_str());
pluginHandle = initStruct->pluginHandle;
return true;
}
Expand All @@ -113,6 +134,9 @@ DLL_EXPORT void plugsetup(PLUG_SETUPSTRUCT* setupStruct)
extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if(fdwReason == DLL_PROCESS_ATTACH)
{
hModule = hinstDLL;
DisableThreadLibraryCalls(hinstDLL);
}
return TRUE;
}

0 comments on commit 4bfb7ca

Please sign in to comment.