1
0
Fork 0

DBG: converted some functions to UTF-8 (now you can debug/comment a file with chinese characters in it)

This commit is contained in:
Mr. eXoDia 2014-09-13 00:28:05 +02:00
parent 0cc9c5a0ce
commit 698005bb81
8 changed files with 52 additions and 37 deletions

View File

@ -26,14 +26,14 @@ static bool _sectionfromaddr(duint addr, char* section)
HMODULE hMod = (HMODULE)modbasefromaddr(addr);
if(!hMod)
return false;
char curModPath[MAX_PATH] = "";
if(!GetModuleFileNameExA(fdProcessInfo->hProcess, hMod, curModPath, MAX_PATH))
wchar_t curModPath[MAX_PATH] = L"";
if(!GetModuleFileNameExW(fdProcessInfo->hProcess, hMod, curModPath, MAX_PATH))
return false;
HANDLE FileHandle;
DWORD LoadedSize;
HANDLE FileMap;
ULONG_PTR FileMapVA;
if(StaticFileLoad(curModPath, UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
if(StaticFileLoadW(curModPath, UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
{
uint rva = addr - (uint)hMod;
int sectionNumber = GetPE32SectionNumberFromVA(FileMapVA, GetPE32DataFromMappedFile(FileMapVA, 0, UE_IMAGEBASE) + rva);
@ -42,10 +42,10 @@ static bool _sectionfromaddr(duint addr, char* section)
const char* name = (const char*)GetPE32DataFromMappedFile(FileMapVA, sectionNumber, UE_SECTIONNAME);
if(section)
strcpy(section, name);
StaticFileUnload(curModPath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
StaticFileUnloadW(curModPath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
return true;
}
StaticFileUnload(curModPath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
StaticFileUnloadW(curModPath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
}
return false;
}
@ -94,7 +94,14 @@ static bool _patchrestore(duint addr)
static int _modpathfromaddr(duint addr, char* path, int size)
{
return GetModuleFileNameExA(fdProcessInfo->hProcess, (HMODULE)modbasefromaddr(addr), path, size);
Memory<wchar_t*> wszModPath(size * sizeof(wchar_t), "_modpathfromaddr:wszModPath");
if(!GetModuleFileNameExW(fdProcessInfo->hProcess, (HMODULE)addr, wszModPath, size))
{
*path = '\0';
return 0;
}
strcpy_s(path, size, ConvertUtf16ToUtf8(wszModPath).c_str());
return (int)strlen(path);
}
static int _modpathfromname(const char* modname, char* path, int size)

View File

@ -155,10 +155,10 @@ bool DirExists(const char* dir)
bool GetFileNameFromHandle(HANDLE hFile, char* szFileName)
{
wchar_t wszFileName[MAX_PATH]=L"";
if(!PathFromFileHandleW(hFile, wszFileName, sizeof(wszFileName)))
return false;
strcpy_s(szFileName, MAX_PATH, ConvertUtf16ToUtf8(wszFileName).c_str());
wchar_t wszFileName[MAX_PATH] = L"";
if(!PathFromFileHandleW(hFile, wszFileName, sizeof(wszFileName)))
return false;
strcpy_s(szFileName, MAX_PATH, ConvertUtf16ToUtf8(wszFileName).c_str());
return true;
}

View File

@ -28,15 +28,29 @@ void dbsave()
functioncachesave(root);
loopcachesave(root);
bpcachesave(root);
std::wstring wdbpath = ConvertUtf8ToUtf16(dbpath);
if(json_object_size(root))
{
json_dump_file(root, dbpath, JSON_INDENT(4));
LZ4_compress_file(dbpath, dbpath);
FILE* jsonFile = 0;
if(_wfopen_s(&jsonFile, wdbpath.c_str(), L"wb"))
{
dputs("failed to open database file for editing!");
json_decref(root); //free root
return;
}
if(json_dumpf(root, jsonFile, JSON_INDENT(4)) == -1)
{
dputs("couldn't write JSON to database file...");
json_decref(root); //free root
return;
}
fclose(jsonFile);
LZ4_compress_fileW(wdbpath.c_str(), wdbpath.c_str());
}
else //remove database when nothing is in there
DeleteFileA(dbpath);
json_decref(root); //free root
DeleteFileW(wdbpath.c_str());
dprintf("%ums\n", GetTickCount() - ticks);
json_decref(root); //free root
}
void dbload()
@ -45,15 +59,23 @@ void dbload()
return;
dprintf("loading database...");
DWORD ticks = GetTickCount();
LZ4_STATUS status = LZ4_decompress_file(dbpath, dbpath);
std::wstring wdbpath = ConvertUtf8ToUtf16(dbpath);
LZ4_STATUS status = LZ4_decompress_fileW(wdbpath.c_str(), wdbpath.c_str());
if(status != LZ4_SUCCESS && status != LZ4_INVALID_ARCHIVE)
{
dputs("\ninvalid database file!");
return;
}
JSON root = json_load_file(dbpath, 0, 0);
FILE* jsonFile = 0;
if(_wfopen_s(&jsonFile, wdbpath.c_str(), L"rb"))
{
dputs("\nfailed to open database file!");
return;
}
JSON root = json_loadf(jsonFile, 0, 0);
fclose(jsonFile);
if(status != LZ4_INVALID_ARCHIVE)
LZ4_compress_file(dbpath, dbpath);
LZ4_compress_fileW(wdbpath.c_str(), wdbpath.c_str());
if(!root)
{
dputs("\ninvalid database file (JSON)!");
@ -87,7 +109,7 @@ bool modload(uint base, uint size, const char* fullpath)
if(!base or !size or !fullpath)
return false;
char name[deflen] = "";
//TODO: utf8
int len = (int)strlen(fullpath);
while(fullpath[len] != '\\' and len)
len--;
@ -117,7 +139,8 @@ bool modload(uint base, uint size, const char* fullpath)
DWORD LoadedSize;
HANDLE FileMap;
ULONG_PTR FileMapVA;
if(StaticFileLoad((char*)fullpath, UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
std::wstring wszFullPath = ConvertUtf8ToUtf16(fullpath);
if(StaticFileLoadW(wszFullPath.c_str(), UE_ACCESS_READ, false, &FileHandle, &LoadedSize, &FileMap, &FileMapVA))
{
info.entry = GetPE32DataFromMappedFile(FileMapVA, 0, UE_OEP) + info.base; //get entry point
int SectionCount = (int)GetPE32DataFromMappedFile(FileMapVA, 0, UE_SECTIONNUMBER);
@ -174,7 +197,7 @@ bool modload(uint base, uint size, const char* fullpath)
info.sections.push_back(curSection);
}
}
StaticFileUnload((char*)fullpath, false, FileHandle, LoadedSize, FileMap, FileMapVA);
StaticFileUnloadW(wszFullPath.c_str(), false, FileHandle, LoadedSize, FileMap, FileMapVA);
}
//add module to list
@ -231,7 +254,6 @@ uint modhashfromva(uint va) //return a unique hash from a VA
uint modhashfromname(const char* mod) //return MODINFO.hash
{
//TODO: utf8
if(!mod or !*mod)
return 0;
int len = (int)strlen(mod);
@ -240,7 +262,6 @@ uint modhashfromname(const char* mod) //return MODINFO.hash
uint modbasefromname(const char* modname)
{
//TODO: utf8
if(!modname or strlen(modname) >= MAX_MODULE_SIZE)
return 0;
for(ModulesInfo::iterator i = modinfo.begin(); i != modinfo.end(); ++i)
@ -781,7 +802,6 @@ void bookmarkcachesave(JSON root)
void bookmarkcacheload(JSON root)
{
//TODO: utf8
bookmarks.clear();
const JSON jsonbookmarks = json_object_get(root, "bookmarks");
if(jsonbookmarks)
@ -944,7 +964,6 @@ void functioncachesave(JSON root)
void functioncacheload(JSON root)
{
//TODO: utf8
functions.clear();
const JSON jsonfunctions = json_object_get(root, "functions");
if(jsonfunctions)
@ -1125,7 +1144,6 @@ void loopcachesave(JSON root)
void loopcacheload(JSON root)
{
//TODO: utf8
loops.clear();
const JSON jsonloops = json_object_get(root, "loops");
if(jsonloops)

View File

@ -25,7 +25,6 @@ formatarg:
*/
void argformat(char* cmd)
{
//TODO: utf8
if(strlen(cmd) >= deflen)
return;
@ -55,7 +54,7 @@ void argformat(char* cmd)
len = (int)strlen(arguments);
for(int i = 0, j = 0; i < len; i++)
{
if(arguments[i] == '"' and arguments[i + 1] == '"')
if(arguments[i] == '"' and arguments[i + 1] == '"') //TODO: fix this
i += 2;
j += sprintf(temp + j, "%c", arguments[i]);
}
@ -161,7 +160,6 @@ void argformat(char* cmd)
*/
int arggetcount(const char* cmd)
{
//TODO: utf8
int len = (int)strlen(cmd);
if(!len or len >= deflen)
return -1;
@ -200,7 +198,6 @@ int arggetcount(const char* cmd)
*/
bool argget(const char* cmd, char* arg, int arg_num, bool optional)
{
//TODO: utf8
if(strlen(cmd) >= deflen)
return false;
int argcount = arggetcount(cmd);

View File

@ -19,7 +19,6 @@ static bool cbUnknown(const char* text, ULONGLONG* value)
bool assemble(uint addr, unsigned char* dest, int* size, const char* instruction, char* error)
{
//TODO: utf8
if(strlen(instruction) >= XEDPARSE_MAXBUFSIZE)
return false;
XEDPARSE parse;

View File

@ -226,7 +226,6 @@ void bpcachesave(JSON root)
void bpcacheload(JSON root)
{
//TODO: utf8
breakpoints.clear();
const JSON jsonbreakpoints = json_object_get(root, "breakpoints");
if(jsonbreakpoints)

View File

@ -46,7 +46,6 @@ void cmdfree(COMMAND* cmd_list)
bool cmdnew(COMMAND* command_list, const char* name, CBCOMMAND cbCommand, bool debugonly)
{
//TODO: utf8
if(!command_list or !cbCommand or !name or !*name or cmdfind(command_list, name, 0))
return false;
COMMAND* cmd;
@ -75,7 +74,6 @@ bool cmdnew(COMMAND* command_list, const char* name, CBCOMMAND cbCommand, bool d
COMMAND* cmdget(COMMAND* command_list, const char* cmd)
{
//TODO: utf8
char new_cmd[deflen] = "";
strcpy_s(new_cmd, cmd);
int len = (int)strlen(new_cmd);
@ -138,7 +136,6 @@ error_is_fatal: error return of a command callback stops the command proce
*/
CMDRESULT cmdloop(COMMAND* command_list, CBCOMMAND cbUnknownCommand, CBCOMMANDPROVIDER cbCommandProvider, CBCOMMANDFINDER cbCommandFinder, bool error_is_fatal)
{
//TODO: utf8
if(!cbUnknownCommand or !cbCommandProvider)
return STATUS_ERROR;
char command[deflen] = "";
@ -208,7 +205,6 @@ static bool isvalidexpression(const char* expression)
static void specialformat(char* string)
{
//TODO: utf8
int len = (int)strlen(string);
char* found = strstr(string, "=");
char* str = (char*)emalloc(len * 2, "specialformat:str");
@ -285,7 +281,6 @@ COMMAND* cmdfindmain(COMMAND* cmd_list, char* command)
CMDRESULT cmddirectexec(COMMAND* cmd_list, const char* cmd)
{
//TODO: utf8
if(!cmd or !strlen(cmd))
return STATUS_ERROR;
char command[deflen] = "";

View File

@ -8,7 +8,7 @@ typedef enum _LZ4_STATUS
LZ4_FAILED_OPEN_OUTPUT,
LZ4_NOT_ENOUGH_MEMORY,
LZ4_INVALID_ARCHIVE,
LZ4_CORRUPTED_ARCHIVE
LZ4_CORRUPTED_ARCHIVE
} LZ4_STATUS;
#if defined (__cplusplus)