Skip to content

Commit

Permalink
GP-4367: Package dbgmodel (ghidradbg) better
Browse files Browse the repository at this point in the history
  • Loading branch information
nsadeveloper789 committed Feb 28, 2024
1 parent 9934159 commit 5b16857
Show file tree
Hide file tree
Showing 21 changed files with 269 additions and 219 deletions.
46 changes: 39 additions & 7 deletions Ghidra/Debug/Debugger-agent-dbgeng/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ apply from: "$rootProject.projectDir/gradle/distributableGhidraModule.gradle"

apply from: "$rootProject.projectDir/gradle/debugger/hasNodepJar.gradle"
apply from: "$rootProject.projectDir/gradle/debugger/hasPythonPackage.gradle"
apply from: "buildNatives.gradle"

apply plugin: 'eclipse'
eclipse.project.name = 'Debug Debugger-agent-dbgeng'
Expand All @@ -37,12 +36,45 @@ dependencies {
testImplementation project(path: ":Debugger-gadp", configuration: 'testArtifacts')
}

// Include buildable native source in distribution
rootProject.assembleDistribution {
from (this.project.projectDir.toString()) {
include "src/**"
into { getZipPath(this.project) }
}
if ("win_x86_64".equals(getCurrentPlatformName())) {

String makeName = "win_x86_64DbgmodelTlbMake"
task(type: Exec, makeName) {
ext.tmpBatch = file("build/buildTlb.bat")
ext.idl = file("src/main/py/src/ghidradbg/dbgmodel/DbgModel.idl")
ext.tlb = file("build/os/win_x86_64/dbgmodel.tlb")
inputs.file(idl)
outputs.file(tlb)

doFirst {
file(tlb).parentFile.mkdirs()
def midlCmd = "midl /tlb ${tlb} ${idl}"
println "Executing: " + midlCmd

tmpBatch.withWriter { out ->
out.println "call " + VISUAL_STUDIO_VCVARS_CMD
out.println midlCmd
}
}
doLast {
assert file(tlb).exists() : "Failed to build dbgmodel.tlb"
}

commandLine "cmd", "/c", tmpBatch
}

tasks.assemblePyPackage {
from(tasks."$makeName") {
into("src/ghidradbg/dbgmodel/tlb")
}
}
}
else {
tasks.assemblePyPackage {
from(rootProject.BIN_REPO + '/' + getGhidraRelativePath(project) + "/os/win_x86_64/dbgmodel.tlb") {
into("src/ghidradbg/dbgmodel/tlb")
}
}
}

tasks.nodepJar {
Expand Down
49 changes: 0 additions & 49 deletions Ghidra/Debug/Debugger-agent-dbgeng/buildNatives.gradle

This file was deleted.

2 changes: 1 addition & 1 deletion Ghidra/Debug/Debugger-agent-dbgeng/certification.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ data/debugger-launchers/local-dbgeng.bat||GHIDRA||||END|
src/main/py/LICENSE||GHIDRA||||END|
src/main/py/README.md||GHIDRA||||END|
src/main/py/pyproject.toml||GHIDRA||||END|
src/main/py/src/dbgmodel/DbgModel.idl||GHIDRA||||END|
src/main/py/src/ghidradbg/dbgmodel/DbgModel.idl||GHIDRA||||END|
src/main/py/src/ghidradbg/schema.xml||GHIDRA||||END|
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers = [
]
dependencies = [
"ghidratrace==10.4",
"pybag>=2.2.8"
"pybag>=2.2.9"
]

[project.urls]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
from . import util, commands, methods, hooks
from dbgmodel.ihostdatamodelaccess import HostDataModelAccess
import ctypes
import platform
import os

# NOTE: libraries must precede EVERYTHING, esp pybag and DbgMod

ctypes.windll.kernel32.SetErrorMode(0x0001 | 0x0002 | 0x8000)

if platform.architecture()[0] == '64bit':
dbgdirs = [os.getenv('OPT_DBGMODEL_PATH'),
r'C:\Program Files\Windows Kits\10\Debuggers\x64',
r'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64']
else:
dbgdirs = [os.getenv('OPT_DBGMODEL_PATH'),
r'C:\Program Files\Windows Kits\10\Debuggers\x86',
r'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86']
dbgdir = None
for _dir in dbgdirs:
if os.path.exists(_dir):
dbgdir = _dir
break

if not dbgdir:
raise RuntimeError("Windbg install directory not found!")

# preload these to get correct DLLs loaded
try:
ctypes.windll.LoadLibrary(os.path.join(dbgdir, 'dbghelp.dll'))
except Exception as exc:
print(f"LoadLibrary failed: {dbgdir}\dbghelp.dll {exc}")
pass
try:
ctypes.windll.LoadLibrary(os.path.join(dbgdir, 'dbgeng.dll'))
except Exception as exc:
print(f"LoadLibrary failed: {dbgdir}\dbgeng.dll {exc}")
pass
try:
ctypes.windll.LoadLibrary(os.path.join(dbgdir, 'DbgModel.dll'))
except Exception as exc:
print(f"LoadLibrary failed: {dbgdir}\dbgmodel.dll {exc}")
pass
from . import libraries, util, commands, methods, hooks
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# limitations under the License.
##
from ghidratrace.client import Address, RegVal

from pybag import pydbg

from . import util


language_map = {
'ARM': ['AARCH64:BE:64:v8A', 'AARCH64:LE:64:AppleSilicon', 'AARCH64:LE:64:v8A', 'ARM:BE:64:v8', 'ARM:LE:64:v8'],
'Itanium': [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import sys
import time

from ghidratrace import sch
from ghidratrace.client import Client, Address, AddressRange, TraceObject
from pybag import pydbg, userdbg, kerneldbg
from pybag.dbgeng import core as DbgEng
from pybag.dbgeng import exception
from dbgmodel.imodelobject import ModelObjectKind

from ghidratrace import sch
from ghidratrace.client import Client, Address, AddressRange, TraceObject

from . import util, arch, methods, hooks
from .dbgmodel.imodelobject import ModelObjectKind


PAGE_SIZE = 4096
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## ###
# IP: GHIDRA
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
import os


def module_locator():
return os.path.dirname(os.path.realpath(__file__))
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
from ctypes import *
from comtypes.hresult import S_OK, S_FALSE
from ctypes import *

from comtypes.gen import DbgMod
from comtypes.hresult import S_OK, S_FALSE
from pybag.dbgeng import exception
import dbgmodel.imodelobject as mo

from . import imodelobject as mo


class DataModelManager(object):
def __init__(self, mgr):
Expand All @@ -41,43 +43,43 @@ def GetRootNamespace(self):

def AcquireNamedModel(self, modelName, modelObject):
raise exception.E_NOTIMPL_Error

def Close(self):
raise exception.E_NOTIMPL_Error

def CreateNoValue(self, object):
raise exception.E_NOTIMPL_Error

def CreateErrorObject(self, error, message, object):
raise exception.E_NOTIMPL_Error

def CreateTypedObject(self, context, objectLocation, objectType, object):
raise exception.E_NOTIMPL_Error

def CreateTypedObjectByReference(self, context, objectLocation, objectType, object):
raise exception.E_NOTIMPL_Error

def CreateSyntheticObject(self, context, object):
raise exception.E_NOTIMPL_Error

def CreateDataModelObject(self, dataModel, object):
raise exception.E_NOTIMPL_Error

def CreateTypedIntrinsicObject(self, intrinsicData, type, object):
raise exception.E_NOTIMPL_Error

def CreateIntrinsicObject(self, objectKind, intrinsicData, object):
raise exception.E_NOTIMPL_Error

def GetModelForTypeSignature(self, typeSignature, dataModel):
raise exception.E_NOTIMPL_Error

def GetModelForType(self, type, dataModel, typeSignature, wildcardMatches):
raise exception.E_NOTIMPL_Error

def RegisterExtensionForTypeSignature(self, typeSignature, dataModel):
raise exception.E_NOTIMPL_Error

def RegisterModelForTypeSignature(self, typeSignature, dataModel):
raise exception.E_NOTIMPL_Error

Expand All @@ -92,5 +94,3 @@ def UnregisterModelForTypeSignature(self, dataModel, typeSignature):

def UnregisterNamedModel(self, modelName):
raise exception.E_NOTIMPL_Error


Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
from ctypes import *
from comtypes.hresult import S_OK, S_FALSE
from ctypes import *

from comtypes.gen import DbgMod
from comtypes.hresult import S_OK, S_FALSE
from pybag.dbgeng import exception
from pybag.dbgeng import win32


class DebugHost(object):
def __init__(self, host):
self._host = host
Expand All @@ -38,11 +39,6 @@ def GetCurrentContext(self, context):

def GetDefaultMetadata(self, metadata):
raise exception.E_NOTIMPL_Error

def GetHostDefinedInterface(self, hostUnk):
raise exception.E_NOTIMPL_Error





Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
from ctypes import *
from comtypes.hresult import S_OK, S_FALSE
from ctypes import *

from comtypes.gen import DbgMod
from comtypes.hresult import S_OK, S_FALSE
from pybag.dbgeng import exception

from .idatamodelmanager import DataModelManager
from .idebughost import DebugHost
from .idebughost import DebugHost


class HostDataModelAccess(object):
def __init__(self, hdma):
Expand All @@ -41,6 +42,3 @@ def GetDataModel(self):
hr = self._hdma.GetDataModel(byref(manager), byref(host))
exception.check_err(hr)
return (DataModelManager(manager), DebugHost(host))



Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
from ctypes import *
from comtypes import COMError
from comtypes.hresult import S_OK, S_FALSE
from ctypes import *

from comtypes import COMError
from comtypes.gen import DbgMod
from comtypes.hresult import S_OK, S_FALSE
from pybag.dbgeng import exception

from .imodeliterator import ModelIterator


class IterableConcept(object):
def __init__(self, concept):
self._concept = concept
concept.AddRef()


# IterableConcept

def GetDefaultIndexDimensionality(self, context, dimensionality):
Expand All @@ -39,6 +40,3 @@ def GetIterator(self, context):
except COMError as ce:
return None
return ModelIterator(iterator)



Loading

0 comments on commit 5b16857

Please sign in to comment.