Revert "Merged in Nukem9/x64_dbg/master (pull request #45)"
This reverts commitb6735aad53
, reversing changes made to20fa55cc2b
.
This commit is contained in:
parent
b6735aad53
commit
4798a29660
|
@ -0,0 +1,93 @@
|
|||
#include <stdio.h>
|
||||
#include <cstring>
|
||||
#include <stdint.h>
|
||||
|
||||
#define uint size_t
|
||||
#define PAGE_SIZE 0x1000
|
||||
|
||||
#ifdef _WIN64
|
||||
#define HIGHEST_USER_ADDR 0x7FFFFFEFFFF
|
||||
#else //x86
|
||||
#define HIGHEST_USER_ADDR 0x7FFEFFFF
|
||||
#endif // _WIN64
|
||||
|
||||
bool readblock(uint addr, unsigned char block[PAGE_SIZE])
|
||||
{
|
||||
printf("readblock(%X[%X])\n", addr, PAGE_SIZE);
|
||||
memset(block, 0xFF, PAGE_SIZE);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool memread(uint addr, unsigned char* data, uint size)
|
||||
{
|
||||
//check if the address is inside user space
|
||||
if(addr > HIGHEST_USER_ADDR)
|
||||
return false;
|
||||
|
||||
puts("-start-");
|
||||
printf(" addr: %X\n size: %X\n", addr, size);
|
||||
|
||||
//calculate the start page
|
||||
uint start = addr & ~(PAGE_SIZE - 1);
|
||||
printf(" start: %X\n", start);
|
||||
|
||||
//calculate the end page
|
||||
uint end = addr + size;
|
||||
uint x = end & (PAGE_SIZE - 1);
|
||||
if(x)
|
||||
end += (PAGE_SIZE - x);
|
||||
printf(" end: %X\n", end);
|
||||
|
||||
//calculate the number of pages to read
|
||||
uint npages = (end - start) / PAGE_SIZE;
|
||||
printf("npages: %d\n\n", npages);
|
||||
|
||||
//go over all pages
|
||||
for(uint i = 0, j = start; i < npages; i++)
|
||||
{
|
||||
//read one page (j should always align with PAGE_SIZE)
|
||||
unsigned char block[PAGE_SIZE];
|
||||
if(!readblock(j, block))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//these are the offsets and sizes in the block to write to append to the output buffer
|
||||
uint roffset = 0;
|
||||
uint rsize = PAGE_SIZE;
|
||||
|
||||
if(i == npages - 1) //last page (first because there might only be one page)
|
||||
{
|
||||
rsize = size - (j - start); //remaining size
|
||||
}
|
||||
else if(i == 0) //first page
|
||||
{
|
||||
roffset = addr & (PAGE_SIZE - 1);
|
||||
rsize = PAGE_SIZE - roffset;
|
||||
}
|
||||
|
||||
printf("roffset: %X\n rsize: %X\n", roffset, rsize);
|
||||
puts("");
|
||||
|
||||
//copy the required block data in the output buffer
|
||||
memcpy(data, block + roffset, rsize);
|
||||
data += rsize;
|
||||
|
||||
j += rsize;
|
||||
}
|
||||
|
||||
puts("--end--\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned char out[0x10000] = {0};
|
||||
memread(0x12A45, out, 0x3456);
|
||||
memread(0x12000, out, 0x456);
|
||||
memread(0x12000, out, 0x3456);
|
||||
memread(0x12000, out, 0x4000);
|
||||
memread(0x12ff0, out, 0x16);
|
||||
memread(0x100, out, 0x3090);
|
||||
return 0;
|
||||
}
|
23
x64_dbg.sln
23
x64_dbg.sln
|
@ -1,8 +1,6 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.31101.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "x64_dbg_bridge", "x64_dbg_bridge\x64_dbg_bridge.vcxproj", "{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "x64_dbg_exe", "x64_dbg_exe\x64_dbg_exe.vcxproj", "{3A22175E-6B72-FDCC-1603-C4A2163C7900}"
|
||||
|
@ -19,39 +17,22 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "x64_dbg_launcher", "x64_dbg
|
|||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}.Debug|x64.Build.0 = Debug|x64
|
||||
{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}.Release|Win32.Build.0 = Release|Win32
|
||||
{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}.Release|x64.ActiveCfg = Release|x64
|
||||
{944D9923-CB1A-6F6C-BCBC-9E00A71954C1}.Release|x64.Build.0 = Release|x64
|
||||
{3A22175E-6B72-FDCC-1603-C4A2163C7900}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{3A22175E-6B72-FDCC-1603-C4A2163C7900}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{3A22175E-6B72-FDCC-1603-C4A2163C7900}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{3A22175E-6B72-FDCC-1603-C4A2163C7900}.Debug|x64.Build.0 = Debug|x64
|
||||
{3A22175E-6B72-FDCC-1603-C4A2163C7900}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{3A22175E-6B72-FDCC-1603-C4A2163C7900}.Release|Win32.Build.0 = Release|Win32
|
||||
{3A22175E-6B72-FDCC-1603-C4A2163C7900}.Release|x64.ActiveCfg = Release|x64
|
||||
{3A22175E-6B72-FDCC-1603-C4A2163C7900}.Release|x64.Build.0 = Release|x64
|
||||
{E6548308-401E-3A8A-5819-905DB90522A6}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{E6548308-401E-3A8A-5819-905DB90522A6}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{E6548308-401E-3A8A-5819-905DB90522A6}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{E6548308-401E-3A8A-5819-905DB90522A6}.Debug|x64.Build.0 = Debug|x64
|
||||
{E6548308-401E-3A8A-5819-905DB90522A6}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{E6548308-401E-3A8A-5819-905DB90522A6}.Release|Win32.Build.0 = Release|Win32
|
||||
{E6548308-401E-3A8A-5819-905DB90522A6}.Release|x64.ActiveCfg = Release|x64
|
||||
{E6548308-401E-3A8A-5819-905DB90522A6}.Release|x64.Build.0 = Release|x64
|
||||
{AC3F927A-4079-4C97-B8BE-8D04546802E7}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{AC3F927A-4079-4C97-B8BE-8D04546802E7}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{AC3F927A-4079-4C97-B8BE-8D04546802E7}.Debug|x64.ActiveCfg = Debug|Win32
|
||||
{AC3F927A-4079-4C97-B8BE-8D04546802E7}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{AC3F927A-4079-4C97-B8BE-8D04546802E7}.Release|Win32.Build.0 = Release|Win32
|
||||
{AC3F927A-4079-4C97-B8BE-8D04546802E7}.Release|x64.ActiveCfg = Release|Win32
|
||||
|
|
|
@ -540,8 +540,8 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
int ThreadNumber;
|
||||
HANDLE Handle;
|
||||
DWORD ThreadId;
|
||||
HANDLE hThread;
|
||||
DWORD dwThreadId;
|
||||
duint ThreadStartAddress;
|
||||
duint ThreadLocalBase;
|
||||
char threadName[MAX_THREAD_NAME_SIZE];
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
|
@ -35,22 +27,10 @@
|
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
@ -58,15 +38,9 @@
|
|||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
|
@ -74,22 +48,11 @@
|
|||
<IntDir>$(Platform)\$(Configuration)\</IntDir>
|
||||
<TargetName>x32_bridge</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)bin\x32\</OutDir>
|
||||
<IntDir>$(Platform)\$(Configuration)\</IntDir>
|
||||
<TargetName>x32_bridge</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)bin\x64\</OutDir>
|
||||
<TargetName>x64_bridge</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)bin\x64\</OutDir>
|
||||
<TargetName>x64_bridge</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>BUILD_BRIDGE;WIN32;NDEBUG;_WINDOWS;_USRDLL;X64_DBG_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
|
@ -106,22 +69,6 @@
|
|||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>BUILD_BRIDGE;WIN32;NDEBUG;_WINDOWS;_USRDLL;X64_DBG_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>BUILD_BRIDGE;WIN32;NDEBUG;_WINDOWS;_USRDLL;X64_DBG_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
|
@ -136,20 +83,6 @@
|
|||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>BUILD_BRIDGE;WIN32;NDEBUG;_WINDOWS;_USRDLL;X64_DBG_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
|
|
@ -5,19 +5,9 @@
|
|||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerCommand>$(OutDir)\x32_dbg.exe</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LocalDebuggerCommand>$(OutDir)\x64_dbg.exe</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerCommand>$(OutDir)\x64_dbg.exe</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -24,7 +24,7 @@ static bool _assembleatex(duint addr, const char* instruction, char* error, bool
|
|||
|
||||
static bool _sectionfromaddr(duint addr, char* section)
|
||||
{
|
||||
HMODULE hMod = (HMODULE)ModBaseFromAddr(addr);
|
||||
HMODULE hMod = (HMODULE)modbasefromaddr(addr);
|
||||
if(!hMod)
|
||||
return false;
|
||||
wchar_t curModPath[MAX_PATH] = L"";
|
||||
|
@ -72,7 +72,7 @@ static bool _patchinrange(duint start, duint end)
|
|||
|
||||
static bool _mempatch(duint va, const unsigned char* src, duint size)
|
||||
{
|
||||
return MemPatch((void*)va, (void*)src, size, 0);
|
||||
return mempatch(fdProcessInfo->hProcess, (void*)va, src, size, 0);
|
||||
}
|
||||
|
||||
static void _patchrestorerange(duint start, duint end)
|
||||
|
@ -162,17 +162,17 @@ bool _getprocesslist(DBGPROCESSINFO** entries, int* count)
|
|||
|
||||
static void _memupdatemap()
|
||||
{
|
||||
MemUpdateMap(fdProcessInfo->hProcess);
|
||||
memupdatemap(fdProcessInfo->hProcess);
|
||||
}
|
||||
|
||||
void dbgfunctionsinit()
|
||||
{
|
||||
_dbgfunctions.AssembleAtEx = _assembleatex;
|
||||
_dbgfunctions.SectionFromAddr = _sectionfromaddr;
|
||||
_dbgfunctions.ModNameFromAddr = ModNameFromAddr;
|
||||
_dbgfunctions.ModBaseFromAddr = ModBaseFromAddr;
|
||||
_dbgfunctions.ModBaseFromName = ModBaseFromName;
|
||||
_dbgfunctions.ModSizeFromAddr = ModSizeFromAddr;
|
||||
_dbgfunctions.ModNameFromAddr = modnamefromaddr;
|
||||
_dbgfunctions.ModBaseFromAddr = modbasefromaddr;
|
||||
_dbgfunctions.ModBaseFromName = modbasefromname;
|
||||
_dbgfunctions.ModSizeFromAddr = modsizefromaddr;
|
||||
_dbgfunctions.Assemble = assemble;
|
||||
_dbgfunctions.PatchGet = _patchget;
|
||||
_dbgfunctions.PatchInRange = _patchinrange;
|
||||
|
@ -181,12 +181,12 @@ void dbgfunctionsinit()
|
|||
_dbgfunctions.PatchEnum = (PATCHENUM)patchenum;
|
||||
_dbgfunctions.PatchRestore = _patchrestore;
|
||||
_dbgfunctions.PatchFile = (PATCHFILE)patchfile;
|
||||
_dbgfunctions.ModPathFromAddr = ModPathFromAddr;
|
||||
_dbgfunctions.ModPathFromName = ModPathFromName;
|
||||
_dbgfunctions.ModPathFromAddr = modpathfromaddr;
|
||||
_dbgfunctions.ModPathFromName = modpathfromname;
|
||||
_dbgfunctions.DisasmFast = disasmfast;
|
||||
_dbgfunctions.MemUpdateMap = _memupdatemap;
|
||||
_dbgfunctions.GetCallStack = _getcallstack;
|
||||
_dbgfunctions.SymbolDownloadAllSymbols = SymDownloadAllSymbols;
|
||||
_dbgfunctions.SymbolDownloadAllSymbols = symdownloadallsymbols;
|
||||
_dbgfunctions.GetJit = _getjit;
|
||||
_dbgfunctions.GetJitAuto = _getjitauto;
|
||||
_dbgfunctions.GetDefJit = dbggetdefjit;
|
||||
|
|
|
@ -26,17 +26,17 @@ static bool bOnlyCipAutoComments = false;
|
|||
|
||||
extern "C" DLL_EXPORT duint _dbg_memfindbaseaddr(duint addr, duint* size)
|
||||
{
|
||||
return MemFindBaseAddr(addr, size);
|
||||
return memfindbaseaddr(addr, size);
|
||||
}
|
||||
|
||||
extern "C" DLL_EXPORT bool _dbg_memread(duint addr, unsigned char* dest, duint size, duint* read)
|
||||
{
|
||||
return MemRead((void*)addr, dest, size, read);
|
||||
return memread(fdProcessInfo->hProcess, (void*)addr, dest, size, read);
|
||||
}
|
||||
|
||||
extern "C" DLL_EXPORT bool _dbg_memwrite(duint addr, const unsigned char* src, duint size, duint* written)
|
||||
{
|
||||
return MemWrite((void*)addr, (void*)src, size, written);
|
||||
return memwrite(fdProcessInfo->hProcess, (void*)addr, src, size, written);
|
||||
}
|
||||
|
||||
extern "C" DLL_EXPORT bool _dbg_memmap(MEMMAP* memmap)
|
||||
|
@ -57,7 +57,7 @@ extern "C" DLL_EXPORT bool _dbg_memmap(MEMMAP* memmap)
|
|||
|
||||
extern "C" DLL_EXPORT bool _dbg_memisvalidreadptr(duint addr)
|
||||
{
|
||||
return MemIsValidReadPtr(addr);
|
||||
return memisvalidreadptr(fdProcessInfo->hProcess, addr);
|
||||
}
|
||||
|
||||
extern "C" DLL_EXPORT bool _dbg_valfromstring(const char* string, duint* value)
|
||||
|
@ -69,7 +69,6 @@ extern "C" DLL_EXPORT bool _dbg_isdebugging()
|
|||
{
|
||||
if(IsFileBeingDebugged())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -94,7 +93,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
bool retval = false;
|
||||
if(addrinfo->flags & flagmodule) //get module
|
||||
{
|
||||
if(ModNameFromAddr(addr, addrinfo->module, false)) //get module name
|
||||
if(modnamefromaddr(addr, addrinfo->module, false)) //get module name
|
||||
retval = true;
|
||||
}
|
||||
if(addrinfo->flags & flaglabel)
|
||||
|
@ -122,7 +121,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
if(disasmfast(addr, &basicinfo) && basicinfo.branch && !basicinfo.call && basicinfo.memory.value) //thing is a JMP
|
||||
{
|
||||
uint val = 0;
|
||||
if(MemRead((void*)basicinfo.memory.value, &val, sizeof(val), 0))
|
||||
if(memread(fdProcessInfo->hProcess, (const void*)basicinfo.memory.value, &val, sizeof(val), 0))
|
||||
{
|
||||
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)val, &displacement, pSymbol) and !displacement)
|
||||
{
|
||||
|
@ -138,12 +137,12 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
}
|
||||
if(addrinfo->flags & flagbookmark)
|
||||
{
|
||||
addrinfo->isbookmark = BookmarkGet(addr);
|
||||
addrinfo->isbookmark = bookmarkget(addr);
|
||||
retval = true;
|
||||
}
|
||||
if(addrinfo->flags & flagfunction)
|
||||
{
|
||||
if(FunctionGet(addr, &addrinfo->function.start, &addrinfo->function.end))
|
||||
if(functionget(addr, &addrinfo->function.start, &addrinfo->function.end))
|
||||
retval = true;
|
||||
}
|
||||
if(addrinfo->flags & flagloop)
|
||||
|
@ -154,7 +153,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
if(addrinfo->flags & flagcomment)
|
||||
{
|
||||
*addrinfo->comment = 0;
|
||||
if(CommentGet(addr, addrinfo->comment))
|
||||
if(commentget(addr, addrinfo->comment))
|
||||
retval = true;
|
||||
else
|
||||
{
|
||||
|
@ -300,15 +299,15 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoset(duint addr, ADDRINFO* addrinfo)
|
|||
}
|
||||
if(addrinfo->flags & flagcomment) //set comment
|
||||
{
|
||||
if(CommentSet(addr, addrinfo->comment, true))
|
||||
if(commentset(addr, addrinfo->comment, true))
|
||||
retval = true;
|
||||
}
|
||||
if(addrinfo->flags & flagbookmark) //set bookmark
|
||||
{
|
||||
if(addrinfo->isbookmark)
|
||||
retval = BookmarkSet(addr, true);
|
||||
retval = bookmarkset(addr, true);
|
||||
else
|
||||
retval = BookmarkDelete(addr);
|
||||
retval = bookmarkdel(addr);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
@ -318,20 +317,20 @@ extern "C" DLL_EXPORT int _dbg_bpgettypeat(duint addr)
|
|||
static uint cacheAddr;
|
||||
static int cacheBpCount;
|
||||
static int cacheResult;
|
||||
int bpcount = BpGetList(nullptr);
|
||||
int bpcount = bpgetlist(0);
|
||||
if(cacheAddr != addr or cacheBpCount != bpcount)
|
||||
{
|
||||
BREAKPOINT bp;
|
||||
cacheAddr = addr;
|
||||
cacheResult = 0;
|
||||
cacheBpCount = bpcount;
|
||||
if(BpGet(addr, BPNORMAL, 0, &bp))
|
||||
if(bpget(addr, BPNORMAL, 0, &bp))
|
||||
if(bp.enabled)
|
||||
cacheResult |= bp_normal;
|
||||
if(BpGet(addr, BPHARDWARE, 0, &bp))
|
||||
if(bpget(addr, BPHARDWARE, 0, &bp))
|
||||
if(bp.enabled)
|
||||
cacheResult |= bp_hardware;
|
||||
if(BpGet(addr, BPMEMORY, 0, &bp))
|
||||
if(bpget(addr, BPMEMORY, 0, &bp))
|
||||
if(bp.enabled)
|
||||
cacheResult |= bp_memory;
|
||||
}
|
||||
|
@ -504,7 +503,7 @@ extern "C" DLL_EXPORT int _dbg_getbplist(BPXTYPE type, BPMAP* bpmap)
|
|||
if(!bpmap)
|
||||
return 0;
|
||||
std::vector<BREAKPOINT> list;
|
||||
int bpcount = BpGetList(&list);
|
||||
int bpcount = bpgetlist(&list);
|
||||
if(bpcount == 0)
|
||||
{
|
||||
bpmap->count = 0;
|
||||
|
@ -567,7 +566,7 @@ extern "C" DLL_EXPORT int _dbg_getbplist(BPXTYPE type, BPMAP* bpmap)
|
|||
curBp.addr = list[i].addr;
|
||||
curBp.enabled = list[i].enabled;
|
||||
//TODO: fix this
|
||||
if(MemIsValidReadPtr(curBp.addr))
|
||||
if(memisvalidreadptr(fdProcessInfo->hProcess, curBp.addr))
|
||||
curBp.active = true;
|
||||
strcpy_s(curBp.mod, list[i].mod);
|
||||
strcpy_s(curBp.name, list[i].name);
|
||||
|
@ -614,7 +613,7 @@ extern "C" DLL_EXPORT uint _dbg_getbranchdestination(uint addr)
|
|||
|
||||
extern "C" DLL_EXPORT bool _dbg_functionoverlaps(uint start, uint end)
|
||||
{
|
||||
return FunctionOverlaps(start, end);
|
||||
return functionoverlaps(start, end);
|
||||
}
|
||||
|
||||
extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* param2)
|
||||
|
@ -690,7 +689,7 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
case DBG_SYMBOL_ENUM:
|
||||
{
|
||||
SYMBOLCBINFO* cbInfo = (SYMBOLCBINFO*)param1;
|
||||
SymEnum(cbInfo->base, cbInfo->cbSymbolEnum, cbInfo->user);
|
||||
symenum(cbInfo->base, cbInfo->cbSymbolEnum, cbInfo->user);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -702,7 +701,7 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
|
||||
case DBG_MODBASE_FROM_NAME:
|
||||
{
|
||||
return ModBaseFromName((const char*)param1);
|
||||
return modbasefromname((const char*)param1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -720,7 +719,7 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
|
||||
case DBG_GET_THREAD_LIST:
|
||||
{
|
||||
ThreadGetList((THREADLIST*)param1);
|
||||
threadgetlist((THREADLIST*)param1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -776,7 +775,7 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
if(!param1 or !param2)
|
||||
return 0;
|
||||
unsigned char data[16];
|
||||
if(!MemRead(param1, data, sizeof(data), 0))
|
||||
if(!memread(fdProcessInfo->hProcess, param1, data, sizeof(data), 0))
|
||||
return 0;
|
||||
DISASM disasm;
|
||||
memset(&disasm, 0, sizeof(disasm));
|
||||
|
@ -805,28 +804,28 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
case DBG_FUNCTION_GET:
|
||||
{
|
||||
FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1;
|
||||
return (uint)FunctionGet(info->addr, &info->start, &info->end);
|
||||
return (uint)functionget(info->addr, &info->start, &info->end);
|
||||
}
|
||||
break;
|
||||
|
||||
case DBG_FUNCTION_OVERLAPS:
|
||||
{
|
||||
FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1;
|
||||
return (uint)FunctionOverlaps(info->start, info->end);
|
||||
return (uint)functionoverlaps(info->start, info->end);
|
||||
}
|
||||
break;
|
||||
|
||||
case DBG_FUNCTION_ADD:
|
||||
{
|
||||
FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1;
|
||||
return (uint)FunctionAdd(info->start, info->end, info->manual);
|
||||
return (uint)functionadd(info->start, info->end, info->manual);
|
||||
}
|
||||
break;
|
||||
|
||||
case DBG_FUNCTION_DEL:
|
||||
{
|
||||
FUNCTION_LOOP_INFO* info = (FUNCTION_LOOP_INFO*)param1;
|
||||
return (uint)FunctionDelete(info->addr);
|
||||
return (uint)functiondel(info->addr);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -867,7 +866,7 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
case DBG_IS_BP_DISABLED:
|
||||
{
|
||||
BREAKPOINT bp;
|
||||
if(BpGet((uint)param1, BPNORMAL, 0, &bp))
|
||||
if(bpget((uint)param1, BPNORMAL, 0, &bp))
|
||||
return !(uint)bp.enabled;
|
||||
return (uint)false;
|
||||
}
|
||||
|
@ -875,13 +874,13 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
|
||||
case DBG_SET_AUTO_COMMENT_AT:
|
||||
{
|
||||
return (uint)CommentSet((uint)param1, (const char*)param2, false);
|
||||
return (uint)commentset((uint)param1, (const char*)param2, false);
|
||||
}
|
||||
break;
|
||||
|
||||
case DBG_DELETE_AUTO_COMMENT_RANGE:
|
||||
{
|
||||
CommentDelRange((uint)param1, (uint)param2);
|
||||
commentdelrange((uint)param1, (uint)param2);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -899,25 +898,25 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
|
||||
case DBG_SET_AUTO_BOOKMARK_AT:
|
||||
{
|
||||
return (uint)BookmarkSet((uint)param1, false);
|
||||
return (uint)bookmarkset((uint)param1, false);
|
||||
}
|
||||
break;
|
||||
|
||||
case DBG_DELETE_AUTO_BOOKMARK_RANGE:
|
||||
{
|
||||
BookmarkDelRange((uint)param1, (uint)param2);
|
||||
bookmarkdelrange((uint)param1, (uint)param2);
|
||||
}
|
||||
break;
|
||||
|
||||
case DBG_SET_AUTO_FUNCTION_AT:
|
||||
{
|
||||
return (uint)FunctionAdd((uint)param1, (uint)param2, false);
|
||||
return (uint)functionadd((uint)param1, (uint)param2, false);
|
||||
}
|
||||
break;
|
||||
|
||||
case DBG_DELETE_AUTO_FUNCTION_RANGE:
|
||||
{
|
||||
FunctionDelRange((uint)param1, (uint)param2);
|
||||
functiondelrange((uint)param1, (uint)param2);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -97,7 +97,9 @@ bool arraycontains(const char* cmd_list, const char* cmd)
|
|||
|
||||
bool scmp(const char* a, const char* b)
|
||||
{
|
||||
return _stricmp(a, b) == 0;
|
||||
if(_stricmp(a, b))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void formathex(char* string)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _GLOBAL_H
|
||||
#define _GLOBAL_H
|
||||
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#define WINVER 0x0501
|
||||
#define _WIN32_IE 0x0500
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
|||
#include <stdarg.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <tlhelp32.h>
|
||||
#include "..\x64_dbg_bridge\bridgemain.h"
|
||||
#include "jansson\jansson.h"
|
||||
|
@ -52,6 +51,42 @@ typedef unsigned long uint;
|
|||
typedef long sint;
|
||||
#endif // _WIN64
|
||||
|
||||
enum BITMASK
|
||||
{
|
||||
BIT1 = 0x1,
|
||||
BIT2 = 0x2,
|
||||
BIT3 = 0x4,
|
||||
BIT4 = 0x8,
|
||||
BIT5 = 0x10,
|
||||
BIT6 = 0x20,
|
||||
BIT7 = 0x40,
|
||||
BIT8 = 0x80,
|
||||
BIT9 = 0x100,
|
||||
BIT10 = 0x200,
|
||||
BIT11 = 0x400,
|
||||
BIT12 = 0x800,
|
||||
BIT13 = 0x1000,
|
||||
BIT14 = 0x2000,
|
||||
BIT15 = 0x4000,
|
||||
BIT16 = 0x8000,
|
||||
BIT17 = 0x10000,
|
||||
BIT18 = 0x20000,
|
||||
BIT19 = 0x40000,
|
||||
BIT20 = 0x80000,
|
||||
BIT21 = 0x100000,
|
||||
BIT22 = 0x200000,
|
||||
BIT23 = 0x400000,
|
||||
BIT24 = 0x800000,
|
||||
BIT25 = 0x1000000,
|
||||
BIT26 = 0x2000000,
|
||||
BIT27 = 0x4000000,
|
||||
BIT28 = 0x8000000,
|
||||
BIT29 = 0x10000000,
|
||||
BIT30 = 0x20000000,
|
||||
BIT31 = 0x40000000,
|
||||
BIT32 = 0x80000000
|
||||
};
|
||||
|
||||
enum arch
|
||||
{
|
||||
notfound,
|
||||
|
|
|
@ -21,12 +21,12 @@ void dbsave()
|
|||
dprintf("saving database...");
|
||||
DWORD ticks = GetTickCount();
|
||||
JSON root = json_object();
|
||||
CommentCacheSave(root);
|
||||
commentcachesave(root);
|
||||
labelcachesave(root);
|
||||
BookmarkCacheSave(root);
|
||||
FunctionCacheSave(root);
|
||||
bookmarkcachesave(root);
|
||||
functioncachesave(root);
|
||||
loopcachesave(root);
|
||||
BpCacheSave(root);
|
||||
bpcachesave(root);
|
||||
WString wdbpath = StringUtils::Utf8ToUtf16(dbpath);
|
||||
if(json_object_size(root))
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ void dbload()
|
|||
return;
|
||||
}
|
||||
FILE* jsonFile = 0;
|
||||
if(_wfopen_s(&jsonFile, wdbpath.c_str(), L"rb") != 0)
|
||||
if(_wfopen_s(&jsonFile, wdbpath.c_str(), L"rb"))
|
||||
{
|
||||
dputs("\nfailed to open database file!");
|
||||
return;
|
||||
|
@ -82,12 +82,12 @@ void dbload()
|
|||
dputs("\ninvalid database file (JSON)!");
|
||||
return;
|
||||
}
|
||||
CommentCacheLoad(root);
|
||||
commentcacheload(root);
|
||||
labelcacheload(root);
|
||||
BookmarkCacheLoad(root);
|
||||
FunctionCacheLoad(root);
|
||||
bookmarkcacheload(root);
|
||||
functioncacheload(root);
|
||||
loopcacheload(root);
|
||||
BpCacheLoad(root);
|
||||
bpcacheload(root);
|
||||
json_decref(root); //free root
|
||||
dprintf("%ums\n", GetTickCount() - ticks);
|
||||
}
|
||||
|
@ -95,12 +95,12 @@ void dbload()
|
|||
void dbclose()
|
||||
{
|
||||
dbsave();
|
||||
CommentClear();
|
||||
commentclear();
|
||||
labelclear();
|
||||
BookmarkClear();
|
||||
FunctionClear();
|
||||
bookmarkclear();
|
||||
functionclear();
|
||||
loopclear();
|
||||
BpClear();
|
||||
bpclear();
|
||||
patchclear();
|
||||
}
|
||||
|
||||
|
@ -111,44 +111,44 @@ bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum)
|
|||
VirtualQueryEx(fdProcessInfo->hProcess, (const void*)base, &mbi, sizeof(mbi));
|
||||
uint size = mbi.RegionSize;
|
||||
Memory<void*> buffer(size, "apienumexports:buffer");
|
||||
if(!MemRead((void*)base, buffer, size, 0))
|
||||
if(!memread(fdProcessInfo->hProcess, (const void*)base, buffer, size, 0))
|
||||
return false;
|
||||
IMAGE_NT_HEADERS* pnth = (IMAGE_NT_HEADERS*)((uint)buffer + GetPE32DataFromMappedFile((ULONG_PTR)buffer, 0, UE_PE_OFFSET));
|
||||
uint export_dir_rva = pnth->OptionalHeader.DataDirectory[0].VirtualAddress;
|
||||
uint export_dir_size = pnth->OptionalHeader.DataDirectory[0].Size;
|
||||
IMAGE_EXPORT_DIRECTORY export_dir;
|
||||
memset(&export_dir, 0, sizeof(export_dir));
|
||||
MemRead((void*)(export_dir_rva + base), &export_dir, sizeof(export_dir), 0);
|
||||
memread(fdProcessInfo->hProcess, (const void*)(export_dir_rva + base), &export_dir, sizeof(export_dir), 0);
|
||||
unsigned int NumberOfNames = export_dir.NumberOfNames;
|
||||
if(!export_dir.NumberOfFunctions or !NumberOfNames) //no named exports
|
||||
return false;
|
||||
char modname[MAX_MODULE_SIZE] = "";
|
||||
ModNameFromAddr(base, modname, true);
|
||||
modnamefromaddr(base, modname, true);
|
||||
uint original_name_va = export_dir.Name + base;
|
||||
char original_name[deflen] = "";
|
||||
memset(original_name, 0, sizeof(original_name));
|
||||
MemRead((void*)original_name_va, original_name, deflen, 0);
|
||||
memread(fdProcessInfo->hProcess, (const void*)original_name_va, original_name, deflen, 0);
|
||||
char* AddrOfFunctions_va = (char*)(export_dir.AddressOfFunctions + base);
|
||||
char* AddrOfNames_va = (char*)(export_dir.AddressOfNames + base);
|
||||
char* AddrOfNameOrdinals_va = (char*)(export_dir.AddressOfNameOrdinals + base);
|
||||
for(DWORD i = 0; i < NumberOfNames; i++)
|
||||
{
|
||||
DWORD curAddrOfName = 0;
|
||||
MemRead(AddrOfNames_va + sizeof(DWORD)*i, &curAddrOfName, sizeof(DWORD), 0);
|
||||
memread(fdProcessInfo->hProcess, AddrOfNames_va + sizeof(DWORD)*i, &curAddrOfName, sizeof(DWORD), 0);
|
||||
char* cur_name_va = (char*)(curAddrOfName + base);
|
||||
char cur_name[deflen] = "";
|
||||
memset(cur_name, 0, deflen);
|
||||
MemRead(cur_name_va, cur_name, deflen, 0);
|
||||
memread(fdProcessInfo->hProcess, cur_name_va, cur_name, deflen, 0);
|
||||
WORD curAddrOfNameOrdinals = 0;
|
||||
MemRead(AddrOfNameOrdinals_va + sizeof(WORD)*i, &curAddrOfNameOrdinals, sizeof(WORD), 0);
|
||||
memread(fdProcessInfo->hProcess, AddrOfNameOrdinals_va + sizeof(WORD)*i, &curAddrOfNameOrdinals, sizeof(WORD), 0);
|
||||
DWORD curFunctionRva = 0;
|
||||
MemRead(AddrOfFunctions_va + sizeof(DWORD)*curAddrOfNameOrdinals, &curFunctionRva, sizeof(DWORD), 0);
|
||||
memread(fdProcessInfo->hProcess, AddrOfFunctions_va + sizeof(DWORD)*curAddrOfNameOrdinals, &curFunctionRva, sizeof(DWORD), 0);
|
||||
|
||||
if(curFunctionRva >= export_dir_rva and curFunctionRva < export_dir_rva + export_dir_size)
|
||||
{
|
||||
char forwarded_api[deflen] = "";
|
||||
memset(forwarded_api, 0, deflen);
|
||||
MemRead((void*)(curFunctionRva + base), forwarded_api, deflen, 0);
|
||||
memread(fdProcessInfo->hProcess, (void*)(curFunctionRva + base), forwarded_api, deflen, 0);
|
||||
int len = (int)strlen(forwarded_api);
|
||||
int j = 0;
|
||||
while(forwarded_api[j] != '.' and j < len)
|
||||
|
|
|
@ -67,12 +67,12 @@ bool assembleat(uint addr, const char* instruction, int* size, char* error, bool
|
|||
if(size)
|
||||
*size = destSize;
|
||||
|
||||
bool ret = MemPatch((void*)addr, dest, destSize, 0);
|
||||
bool ret = mempatch(fdProcessInfo->hProcess, (void*)addr, dest, destSize, 0);
|
||||
if(ret && fillnop && nopsize)
|
||||
{
|
||||
if(size)
|
||||
*size += nopsize;
|
||||
if(!MemPatch((void*)(addr + destSize), nops, nopsize, 0))
|
||||
if(!mempatch(fdProcessInfo->hProcess, (void*)(addr + destSize), nops, nopsize, 0))
|
||||
ret = false;
|
||||
}
|
||||
GuiUpdatePatches();
|
||||
|
|
|
@ -4,206 +4,159 @@
|
|||
#include "debugger.h"
|
||||
#include "memory.h"
|
||||
|
||||
typedef std::unordered_map<uint, BOOKMARKSINFO> BookmarksInfo;
|
||||
typedef std::map<uint, BOOKMARKSINFO> BookmarksInfo;
|
||||
|
||||
static BookmarksInfo bookmarks;
|
||||
|
||||
bool BookmarkSet(uint Address, bool Manual)
|
||||
bool bookmarkset(uint addr, bool manual)
|
||||
{
|
||||
// CHECK: Export call
|
||||
if(!DbgIsDebugging())
|
||||
if(!DbgIsDebugging() or !memisvalidreadptr(fdProcessInfo->hProcess, addr))
|
||||
return false;
|
||||
|
||||
// Validate the incoming address
|
||||
if(!MemIsValidReadPtr(Address))
|
||||
return false;
|
||||
|
||||
BOOKMARKSINFO bookmark;
|
||||
ModNameFromAddr(Address, bookmark.mod, true);
|
||||
bookmark.addr = Address;
|
||||
bookmark.manual = Manual;
|
||||
|
||||
// Exclusive lock to insert new data
|
||||
EXCLUSIVE_ACQUIRE(LockBookmarks);
|
||||
|
||||
if(!bookmarks.insert(std::make_pair(Address, bookmark)).second)
|
||||
return BookmarkDelete(Address);
|
||||
|
||||
modnamefromaddr(addr, bookmark.mod, true);
|
||||
bookmark.addr = addr - modbasefromaddr(addr);
|
||||
bookmark.manual = manual;
|
||||
CriticalSectionLocker locker(LockBookmarks);
|
||||
if(!bookmarks.insert(std::make_pair(modhashfromva(addr), bookmark)).second)
|
||||
return bookmarkdel(addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BookmarkGet(uint Address)
|
||||
bool bookmarkget(uint addr)
|
||||
{
|
||||
// CHECK: Export call
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
|
||||
SHARED_ACQUIRE(LockBookmarks);
|
||||
return (bookmarks.count(Address) > 0);
|
||||
CriticalSectionLocker locker(LockBookmarks);
|
||||
if(bookmarks.count(modhashfromva(addr)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BookmarkDelete(uint Address)
|
||||
bool bookmarkdel(uint addr)
|
||||
{
|
||||
// CHECK: Export call
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
|
||||
EXCLUSIVE_ACQUIRE(LockBookmarks);
|
||||
return (bookmarks.erase(Address) > 0);
|
||||
CriticalSectionLocker locker(LockBookmarks);
|
||||
return (bookmarks.erase(modhashfromva(addr)) > 0);
|
||||
}
|
||||
|
||||
void BookmarkDelRange(uint Start, uint End)
|
||||
void bookmarkdelrange(uint start, uint end)
|
||||
{
|
||||
// CHECK: Export call
|
||||
if(!DbgIsDebugging())
|
||||
return;
|
||||
|
||||
// Are all bookmarks going to be deleted?
|
||||
// 0x00000000 - 0xFFFFFFFF
|
||||
if(Start == 0 && End == ~0)
|
||||
bool bDelAll = (start == 0 && end == ~0); //0x00000000-0xFFFFFFFF
|
||||
uint modbase = modbasefromaddr(start);
|
||||
if(modbase != modbasefromaddr(end))
|
||||
return;
|
||||
start -= modbase;
|
||||
end -= modbase;
|
||||
CriticalSectionLocker locker(LockBookmarks);
|
||||
BookmarksInfo::iterator i = bookmarks.begin();
|
||||
while(i != bookmarks.end())
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockBookmarks);
|
||||
bookmarks.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make sure 'Start' and 'End' reference the same module
|
||||
uint moduleBase = ModBaseFromAddr(Start);
|
||||
|
||||
if(moduleBase != ModBaseFromAddr(End))
|
||||
return;
|
||||
|
||||
EXCLUSIVE_ACQUIRE(LockBookmarks);
|
||||
for(auto itr = bookmarks.begin(); itr != bookmarks.end();)
|
||||
if(i->second.manual) //ignore manual
|
||||
{
|
||||
// Ignore manually set entries
|
||||
if(itr->second.manual)
|
||||
{
|
||||
itr++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// [Start, End)
|
||||
if(itr->second.addr >= Start && itr->second.addr < End)
|
||||
itr = bookmarks.erase(itr);
|
||||
else
|
||||
itr++;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkCacheSave(JSON Root)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockBookmarks);
|
||||
|
||||
const JSON jsonBookmarks = json_array();
|
||||
const JSON jsonAutoBookmarks = json_array();
|
||||
|
||||
// Save to the JSON root
|
||||
for(auto & itr : bookmarks)
|
||||
{
|
||||
JSON currentBookmark = json_object();
|
||||
|
||||
// The address must be adjusted to use an offset
|
||||
// OFFSET = ADDRESS - MOD_BASE
|
||||
uint virtualOffset = itr.second.addr - ModBaseFromAddr(itr.second.addr);
|
||||
|
||||
json_object_set_new(currentBookmark, "module", json_string(itr.second.mod));
|
||||
json_object_set_new(currentBookmark, "address", json_hex(virtualOffset));
|
||||
|
||||
if(itr.second.manual)
|
||||
json_array_append_new(jsonBookmarks, currentBookmark);
|
||||
if(bDelAll || (i->second.addr >= start && i->second.addr < end))
|
||||
bookmarks.erase(i++);
|
||||
else
|
||||
json_array_append_new(jsonAutoBookmarks, currentBookmark);
|
||||
i++;
|
||||
}
|
||||
|
||||
if(json_array_size(jsonBookmarks))
|
||||
json_object_set(Root, "bookmarks", jsonBookmarks);
|
||||
|
||||
if(json_array_size(jsonAutoBookmarks))
|
||||
json_object_set(Root, "autobookmarks", jsonAutoBookmarks);
|
||||
|
||||
json_decref(jsonBookmarks);
|
||||
json_decref(jsonAutoBookmarks);
|
||||
}
|
||||
|
||||
void BookmarkCacheLoad(JSON Root)
|
||||
void bookmarkcachesave(JSON root)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockBookmarks);
|
||||
CriticalSectionLocker locker(LockBookmarks);
|
||||
const JSON jsonbookmarks = json_array();
|
||||
const JSON jsonautobookmarks = json_array();
|
||||
for(BookmarksInfo::iterator i = bookmarks.begin(); i != bookmarks.end(); ++i)
|
||||
{
|
||||
const BOOKMARKSINFO curBookmark = i->second;
|
||||
JSON curjsonbookmark = json_object();
|
||||
json_object_set_new(curjsonbookmark, "module", json_string(curBookmark.mod));
|
||||
json_object_set_new(curjsonbookmark, "address", json_hex(curBookmark.addr));
|
||||
if(curBookmark.manual)
|
||||
json_array_append_new(jsonbookmarks, curjsonbookmark);
|
||||
else
|
||||
json_array_append_new(jsonautobookmarks, curjsonbookmark);
|
||||
}
|
||||
if(json_array_size(jsonbookmarks))
|
||||
json_object_set(root, "bookmarks", jsonbookmarks);
|
||||
json_decref(jsonbookmarks);
|
||||
if(json_array_size(jsonautobookmarks))
|
||||
json_object_set(root, "autobookmarks", jsonautobookmarks);
|
||||
json_decref(jsonautobookmarks);
|
||||
}
|
||||
|
||||
// Inline lambda to parse each JSON entry
|
||||
auto AddBookmarks = [](const JSON Object, bool Manual)
|
||||
void bookmarkcacheload(JSON root)
|
||||
{
|
||||
CriticalSectionLocker locker(LockBookmarks);
|
||||
bookmarks.clear();
|
||||
const JSON jsonbookmarks = json_object_get(root, "bookmarks");
|
||||
if(jsonbookmarks)
|
||||
{
|
||||
size_t i;
|
||||
JSON value;
|
||||
|
||||
json_array_foreach(Object, i, value)
|
||||
json_array_foreach(jsonbookmarks, i, value)
|
||||
{
|
||||
BOOKMARKSINFO bookmarkInfo;
|
||||
memset(&bookmarkInfo, 0, sizeof(BOOKMARKSINFO));
|
||||
|
||||
// Load the module name
|
||||
BOOKMARKSINFO curBookmark;
|
||||
const char* mod = json_string_value(json_object_get(value, "module"));
|
||||
|
||||
if(mod && *mod && strlen(mod) < MAX_MODULE_SIZE)
|
||||
strcpy_s(bookmarkInfo.mod, mod);
|
||||
|
||||
// Load address and set auto-generated flag
|
||||
bookmarkInfo.addr = (uint)json_hex_value(json_object_get(value, "address"));
|
||||
bookmarkInfo.manual = Manual;
|
||||
|
||||
// The offset must be adjusted to use virtual addressing
|
||||
// ADDRESS = OFFSET + MOD_BASE
|
||||
bookmarkInfo.addr += ModBaseFromName(bookmarkInfo.mod);
|
||||
|
||||
bookmarks.insert(std::make_pair(bookmarkInfo.addr, bookmarkInfo));
|
||||
strcpy_s(curBookmark.mod, mod);
|
||||
else
|
||||
*curBookmark.mod = '\0';
|
||||
curBookmark.addr = (uint)json_hex_value(json_object_get(value, "address"));
|
||||
curBookmark.manual = true;
|
||||
const uint key = modhashfromname(curBookmark.mod) + curBookmark.addr;
|
||||
bookmarks.insert(std::make_pair(key, curBookmark));
|
||||
}
|
||||
};
|
||||
|
||||
// Remove existing entries
|
||||
bookmarks.clear();
|
||||
|
||||
const JSON jsonBookmarks = json_object_get(Root, "bookmarks");
|
||||
const JSON jsonAutoBookmarks = json_object_get(Root, "autobookmarks");
|
||||
|
||||
// Load user-set bookmarks
|
||||
if(jsonBookmarks)
|
||||
AddBookmarks(jsonBookmarks, true);
|
||||
|
||||
// Load auto-set bookmarks
|
||||
if(jsonAutoBookmarks)
|
||||
AddBookmarks(jsonAutoBookmarks, false);
|
||||
}
|
||||
JSON jsonautobookmarks = json_object_get(root, "autobookmarks");
|
||||
if(jsonautobookmarks)
|
||||
{
|
||||
size_t i;
|
||||
JSON value;
|
||||
json_array_foreach(jsonautobookmarks, i, value)
|
||||
{
|
||||
BOOKMARKSINFO curBookmark;
|
||||
const char* mod = json_string_value(json_object_get(value, "module"));
|
||||
if(mod && *mod && strlen(mod) < MAX_MODULE_SIZE)
|
||||
strcpy_s(curBookmark.mod, mod);
|
||||
else
|
||||
*curBookmark.mod = '\0';
|
||||
curBookmark.addr = (uint)json_hex_value(json_object_get(value, "address"));
|
||||
curBookmark.manual = false;
|
||||
const uint key = modhashfromname(curBookmark.mod) + curBookmark.addr;
|
||||
bookmarks.insert(std::make_pair(key, curBookmark));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool BookmarkEnum(BOOKMARKSINFO* List, size_t* Size)
|
||||
bool bookmarkenum(BOOKMARKSINFO* bookmarklist, size_t* cbsize)
|
||||
{
|
||||
// The array container must be set, or the size must be set, or both
|
||||
if(!List && !Size)
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
|
||||
SHARED_ACQUIRE(LockBookmarks);
|
||||
|
||||
// Return the size if set
|
||||
if(Size)
|
||||
if(!bookmarklist && !cbsize)
|
||||
return false;
|
||||
CriticalSectionLocker locker(LockBookmarks);
|
||||
if(!bookmarklist && cbsize)
|
||||
{
|
||||
*Size = bookmarks.size() * sizeof(BOOKMARKSINFO);
|
||||
|
||||
if(!List)
|
||||
return true;
|
||||
*cbsize = bookmarks.size() * sizeof(BOOKMARKSINFO);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Copy struct over
|
||||
for(auto & itr : bookmarks)
|
||||
int j = 0;
|
||||
for(BookmarksInfo::iterator i = bookmarks.begin(); i != bookmarks.end(); ++i, j++)
|
||||
{
|
||||
*List = itr.second;
|
||||
List++;
|
||||
bookmarklist[j] = i->second;
|
||||
bookmarklist[j].addr += modbasefromname(bookmarklist[j].mod);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BookmarkClear()
|
||||
void bookmarkclear()
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockBookmarks);
|
||||
bookmarks.clear();
|
||||
CriticalSectionLocker locker(LockBookmarks);
|
||||
BookmarksInfo().swap(bookmarks);
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#ifndef _BOOKMARK_H
|
||||
#define _BOOKMARK_H
|
||||
|
||||
#include "_global.h"
|
||||
|
||||
|
@ -9,11 +10,13 @@ struct BOOKMARKSINFO
|
|||
bool manual;
|
||||
};
|
||||
|
||||
bool BookmarkSet(uint Address, bool Manual);
|
||||
bool BookmarkGet(uint Address);
|
||||
bool BookmarkDelete(uint Address);
|
||||
void BookmarkDelRange(uint Start, uint End);
|
||||
void BookmarkCacheSave(JSON Root);
|
||||
void BookmarkCacheLoad(JSON Root);
|
||||
bool BookmarkEnum(BOOKMARKSINFO* List, size_t* Size);
|
||||
void BookmarkClear();
|
||||
bool bookmarkset(uint addr, bool manual);
|
||||
bool bookmarkget(uint addr);
|
||||
bool bookmarkdel(uint addr);
|
||||
void bookmarkdelrange(uint start, uint end);
|
||||
void bookmarkcachesave(JSON root);
|
||||
void bookmarkcacheload(JSON root);
|
||||
bool bookmarkenum(BOOKMARKSINFO* bookmarklist, size_t* cbsize);
|
||||
void bookmarkclear();
|
||||
|
||||
#endif //_BOOKMARK_H
|
|
@ -11,385 +11,266 @@ typedef std::map<BreakpointKey, BREAKPOINT> BreakpointsInfo;
|
|||
|
||||
static BreakpointsInfo breakpoints;
|
||||
|
||||
BREAKPOINT* BpInfoFromAddr(BP_TYPE Type, uint Address)
|
||||
{
|
||||
//
|
||||
// NOTE: THIS DOES _NOT_ USE LOCKS
|
||||
//
|
||||
auto found = breakpoints.find(BreakpointKey(Type, ModHashFromAddr(Address)));
|
||||
|
||||
// Was the module found with this address?
|
||||
if(found == breakpoints.end())
|
||||
return nullptr;
|
||||
|
||||
return &found->second;
|
||||
}
|
||||
|
||||
int BpGetList(std::vector<BREAKPOINT>* List)
|
||||
{
|
||||
// CHECK: Exported function
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
|
||||
SHARED_ACQUIRE(LockBreakpoints);
|
||||
|
||||
// Did the caller request an output?
|
||||
if(List)
|
||||
{
|
||||
// Enumerate all breakpoints in the global list, fixing the relative
|
||||
// offset to a virtual address
|
||||
for(auto & i : breakpoints)
|
||||
{
|
||||
BREAKPOINT currentBp = i.second;
|
||||
currentBp.addr += ModBaseFromName(currentBp.mod);
|
||||
currentBp.active = MemIsValidReadPtr(currentBp.addr);
|
||||
|
||||
List->push_back(currentBp);
|
||||
}
|
||||
}
|
||||
|
||||
return (int)breakpoints.size();
|
||||
}
|
||||
|
||||
bool BpNew(uint Address, bool Enable, bool Singleshot, short OldBytes, BP_TYPE Type, DWORD TitanType, const char* Name)
|
||||
{
|
||||
// CHECK: Command function
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
|
||||
// Fail if the address is a bad memory region
|
||||
if(!MemIsValidReadPtr(Address))
|
||||
return false;
|
||||
|
||||
// Fail if the breakpoint already exists
|
||||
if(BpGet(Address, Type, Name, nullptr))
|
||||
return false;
|
||||
|
||||
// Default to an empty name if one wasn't supplied
|
||||
if(!Name)
|
||||
Name = "";
|
||||
|
||||
BREAKPOINT bp;
|
||||
memset(&bp, 0, sizeof(BREAKPOINT));
|
||||
|
||||
ModNameFromAddr(Address, bp.mod, true);
|
||||
strcpy_s(bp.name, Name);
|
||||
|
||||
bp.active = true;
|
||||
bp.addr = Address - ModBaseFromAddr(Address);
|
||||
bp.enabled = Enable;
|
||||
bp.oldbytes = OldBytes;
|
||||
bp.singleshoot = Singleshot;
|
||||
bp.titantype = TitanType;
|
||||
bp.type = Type;
|
||||
|
||||
// Insert new entry to the global list
|
||||
EXCLUSIVE_ACQUIRE(LockBreakpoints);
|
||||
|
||||
breakpoints.insert(std::make_pair(BreakpointKey(Type, ModHashFromAddr(Address)), bp));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BpGet(uint Address, BP_TYPE Type, const char* Name, BREAKPOINT* Bp)
|
||||
{
|
||||
// CHECK: Export/Command function
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
|
||||
SHARED_ACQUIRE(LockBreakpoints);
|
||||
|
||||
// Name is optional
|
||||
if(!Name || Name[0] == '\0')
|
||||
{
|
||||
// Perform a lookup by address only
|
||||
BREAKPOINT* bpInfo = BpInfoFromAddr(Type, Address);
|
||||
|
||||
if(!bpInfo)
|
||||
return false;
|
||||
|
||||
// Succeed even if the user didn't request anything
|
||||
if(!Bp)
|
||||
return true;
|
||||
|
||||
*Bp = *bpInfo;
|
||||
Bp->addr += ModBaseFromAddr(Address);
|
||||
Bp->active = MemIsValidReadPtr(Bp->addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Do a lookup by breakpoint name
|
||||
for(auto & i : breakpoints)
|
||||
{
|
||||
// Do the names match?
|
||||
if(strcmp(Name, i.second.name) != 0)
|
||||
continue;
|
||||
|
||||
// Fill out the optional user buffer
|
||||
if(Bp)
|
||||
{
|
||||
*Bp = i.second;
|
||||
Bp->addr += ModBaseFromAddr(Address);
|
||||
Bp->active = MemIsValidReadPtr(Bp->addr);
|
||||
}
|
||||
|
||||
// Return true if the name was found at all
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BpDelete(uint Address, BP_TYPE Type)
|
||||
{
|
||||
// CHECK: Command function
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
|
||||
// Erase the index from the global list
|
||||
EXCLUSIVE_ACQUIRE(LockBreakpoints);
|
||||
|
||||
return (breakpoints.erase(BreakpointKey(Type, ModHashFromAddr(Address))) > 0);
|
||||
}
|
||||
|
||||
bool BpEnable(uint Address, BP_TYPE Type, bool Enable)
|
||||
{
|
||||
// CHECK: Command function
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
|
||||
EXCLUSIVE_ACQUIRE(LockBreakpoints);
|
||||
|
||||
// Check if the breakpoint exists first
|
||||
BREAKPOINT* bpInfo = BpInfoFromAddr(Type, Address);
|
||||
|
||||