GithubHelp home page GithubHelp logo

x64dbg / x64dbgpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from realgam3/x64dbg-python

1.4K 916.0 69.0 2.52 MB

Automating x64dbg using Python, Snapshots:

Home Page: https://ci.appveyor.com/project/mrexodia/x64dbg-python/build/artifacts

License: MIT License

Shell 0.07% Batchfile 0.19% C++ 8.66% C 64.12% Python 3.76% SWIG 22.88% Makefile 0.31%
x64dbg-plugin

x64dbgpy's Introduction

x64dbgpy

Build status

Automating x64dbg using Python.

Works with: http://releases.x64dbg.com

Get PyQt5 here. Video tutorial here.

To develop you will need:

  1. Visual Studio 2015 Community: https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx
  2. Python 2.7 x64 + x86 && pip (Python 2.7.10 has pip on it) - https://www.python.org/downloads/release/python-2710/
  3. Microsoft Visual C++ Compiler for Python 2.7: http://www.microsoft.com/en-us/download/details.aspx?id=44266
  4. PyCharm Community Edition (If you are python developer) : https://www.jetbrains.com/pycharm/download/

To install and test:

  1. Install Python 2.7.10 (x64 + x86) In seperate folders
  2. Install Visual Studio 2015 Community.
  3. Open setenv.bat from the project folder.
  4. Compile the win32 and win64 dlls.
  5. Copy the release folder from the snapshot to the project directory.
  6. Run install32.bat and install64.bat.

Contributors:

  1. Run install.bat (git hook for code buetify)
  2. Test your code
  3. Read PEP8: https://www.python.org/dev/peps/pep-0008/

Example scripts:

Help:

  • I need help with the swig / cpp development,
  • Translating the event callbacks to swig and use it without the code in py.cpp file.
  • Connecting ipython interpreter to x64dbgpy.
  • Python multiprocessing with x64dbgpy plugin (Python embedded).

x64dbgpy's People

Contributors

a1ext avatar andoryuuta avatar herosi avatar lfriede avatar mrexodia avatar realgam3 avatar tachiorz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

x64dbgpy's Issues

Problems setting up project

I am currently struggeling with the setup of this project on a current Windows 10 64bit VM.
I already performed the following steps:

  1. recursive clone of the project
  2. installed VS 2015
  3. installed Python2.7 32 bit and 64 bit version and added both to PATH (used setenv.bat)

Via VS2015 Developer command prompt I tried to run the script install32.bat. At least, that what I think I should do, according to your instructions in README.
Unfortunately, I get the following error message:

c:\x64dbgpy>.\install32.bat
A subdirectory or file c:\x64dbgpy\release\x32\plugins already exists.
        1 file(s) copied.
        1 file(s) copied.
        1 file(s) copied.
Could Not Find c:\x64dbgpy\swig\x64dbg_wrap.cpp
Could Not Find c:\x64dbgpy\swig\x64dbgpy\pluginsdk\x64dbg.py
The system cannot find the file specified.

SUCCESS: Specified value was saved.

SUCCESS: Specified value was saved.

c:\x64dbgpy\swig>call "C:\Users\Master\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat" x86
The system cannot find the path specified.

c:\x64dbgpy\swig>set PYTHONHOME=C:\Python27\

c:\x64dbgpy\swig>"C:\Python27\\python.exe" setup.py  install --install-lib="c:\x64dbgpy\release\x32\plugins"\x64dbgpy
running install
running build
running build_ext
building 'x64dbgpy.pluginsdk._x64dbg' extension
swigging x64dbg.i to x64dbg_wrap.cpp
swig.exe -python -Wall -c++ -outputtuple -outdir x64dbgpy\pluginsdk  -o x64dbg_wrap.cpp x64dbg.i
error: command 'swig.exe' failed: No such file or directory

c:\x64dbgpy>copy bin\x32\scriptapi.pyd "c:\x64dbgpy\release\x32\plugins"\x64dbgpy\
The system cannot find the path specified.
        0 file(s) copied.

I already tried to build the project in VS 2015 and it looks like it worked. Output from VS:

1>------ Rebuild All started: Project: x64dbgpy, Configuration: Release Win32 ------
2>------ Rebuild All started: Project: scriptapi, Configuration: Release Win32 ------
1>  pluginmain.cpp
1>  py.cpp
1>  stringutils.cpp
1>  Generating Code...
1>     Creating library C:\x64dbgpy\bin\x32\x64dbgpy.lib and object C:\x64dbgpy\bin\x32\x64dbgpy.exp
2>  scriptapi.cpp
1>  x64dbgpy.vcxproj -> C:\x64dbgpy\bin\x32\x64dbgpy.dp32
1>  x64dbgpy.vcxproj -> C:\x64dbgpy\bin\x32\x64dbgpy.pdb (Full PDB)
2>     Creating library C:\x64dbgpy\bin\x32\scriptapi.lib and object C:\x64dbgpy\bin\x32\scriptapi.exp
2>  Generating code
2>  All 6550 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
2>  Finished generating code
2>  scriptapi.vcxproj -> C:\x64dbgpy\bin\x32\scriptapi.pyd
2>  scriptapi.vcxproj -> C:\x64dbgpy\bin\x32\scriptapi.pdb (Full PDB)
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========

Could you please assist here?
Thanks in advance.

problem in accessing callback_args in callback function.

from x64dbgpy.__breakpoints import *
bp = Breakpoint()
bp.add(address,func_callback,bp_type=NORMAL,hw_type=EXECUTE,callback_args=(param1,param2,param3))

def func_callback(*callback_args):
print callback_args

getting empty tuple.callback_args = ()

Appveyor snapshots expired

The appveyor snapshots are stored only 6 months, so they've recently expired and currently there is no way to download a recent compiled version of x64dbgpy.

script help

Some of the modules don't know how to use it.
Are there any help documents.
For example, find binary feature codes in memory.
Find two suspicious functions, but I don't know how to use it.

def Find(data, pattern):
    return _x64dbg.Find(data, pattern)

def FindMem(start, size, pattern):
    return _x64dbg.FindMem(start, size, pattern)

Script help

Hello!
I need to implement a memory search from a script similar to this: 001, the result of which is this: 002

I found several functions that should help me with this:

  • DbgMemMap;
  • FindMem or Find.

Using:

import x64dbgpy.pluginsdk._scriptapi.pattern as Pattern
import x64dbgpy.pluginsdk.x64dbg as X64
"""===================================================================="""
X64.GuiLogClear ()
"""===================================================================="""
mm = X64.MEMMAP ()
temp = X64.DbgMemMap (mm)
print (temp)
print (mm.count)
"""===================================================================="""
start = int ("03A10000", 16)
print (start)
print (hex (start))
res = Pattern.FindMem (start, 5, "GET /")
print (hex (res))
res = Pattern.Find ("GET /", 5)
print (res)

I get the following:63647286-714c7980-c727-11e9-966c-e3dc50a0af8d

Question:

  1. How should I use FindMem or Find to get the result?
  2. How to go from MEMMAP to each MEMPAGE and get its start address and size block?

Or should my problem be solved in another way?

no memory r/w access breakpoint api

Hi!
first of all, I want to say thank you.
it's really helpful for unpacking programs. ( unpacking really fun !)

is exist memory r/w access breakpoint api?
memory r/w access breakpoint means breakpoint on one section.

SCRIPT_EXPORT bool SetBreakpoint(duint address);
SCRIPT_EXPORT bool DeleteBreakpoint(duint address);
SCRIPT_EXPORT bool DisableBreakpoint(duint address);
SCRIPT_EXPORT bool SetHardwareBreakpoint(duint address, HardwareType type = HardwareExecute);
SCRIPT_EXPORT bool DeleteHardwareBreakpoint(duint address);

SetBreakpoint api looks like software breakpoint.
and SetHardwareBreakpoint is Hardwarebreakpoint.

if you add script api about r/w access, I'm really thankful
Best regards.

A package error

[PYTHON] Exception...
Traceback (most recent call last):
File "C:\SoftFolder\release\x32\plugins\x64dbgpy\x64dbg_editor\x64dbg_editor.py", line 56, in
import icons.ico
ImportError: No module named ico

Print via stream is broken after exception

Regarding the last commit :
0cba3ac

After an exception the print output is broken... need to restart x64dbg.

A bugggy script ...

Traceback (most recent call last):
  File "\\vmware-host\Shared Folders\VmShared\UNPA~97B.PY", line 189, in <module>
    resume()
  File "\\vmware-host\Shared Folders\VmShared\UNPA~97B.PY", line 59, in resume
    DbgCmdExecDirect("run")  # Run as is for thread issues
NameError: global name 'DbgCmdExecDirect' is not defined

Then i do a print "toto", toto is written but after it a traceback occurs.

totoTraceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\PROGRA~1\x96dbg\release\x32\plugins\x64dbgpy\x64dbgpy\hooks.py", line 44, in write
    self.__original_stream.write(text)
IOError: [Errno 0] Error

Thread-safety

If I call x64dbgpy.pluginsdk.debug.Run() from breakpoint callback, x64dbg debug thread hangs (the UI still works). Is there a proper way to do that?

pluginsdk.debug.StepOver(), pluginsdk.debug.Run() seem not to work in Open GUI or Open Async script

This works until I call pluginsdk.debug.StepOver() or pluginsdk.debug.Run in bp_callback. Everything just hangs or is not responding anymore. If I run these two commands from x64dbg GUI everything works as expected. Tried to execute as GUI and async script, seems there is no difference, am I missing something here?

`import threading
bpAddress = 0x00007FF6EFB1F4D0

def bp_callback():
print("tid={num:d} 0x{num:X}".format(num=threading.currentThread().ident))
global bpAddress
pluginsdk.bridgemain.GuiLogClear()
print("rcx={num:d} 0x{num:X}".format(num=Register.RCX))
print("rdx={num:d} 0x{num:X}".format(num=Register.RDX))

#Breakpoint.remove(bpAddress)
#pluginsdk.debug.Run()
#pluginsdk.debug.Wait()
#pluginsdk.debug.Stop()
#pluginsdk.debug.StepIn()
#pluginsdk.debug.StepOut()
#pluginsdk.debug.StepOver()

Breakpoint.add(bpAddress, bp_callback)`

Break infinite loop

Sometime there is an accident while coding (for example infinite loop) cause the python hanging. It would be nice if there is a button/command to stop current python code.

Not working on 64-bit?

Just tried the Python command line on latest x64dbg snapshot, and no Python commands are giving any output in the log. It also seems they are not taking effect.

Breakpoint callback hangs debugger if a call to debug.Run() is issued.

The below code should cause a hang which requires forceful termination of x86dbg.

`
import struct
from ctypes import *
from x64dbgpy import *
from x64dbgpy.pluginsdk._scriptapi.debug import *
from x64dbgpy.pluginsdk._scriptapi.register import *
from x64dbgpy.pluginsdk._scriptapi.memory import *
#from x64dbgpy._breakpoints import *

def imp_dump():

imp_num_addr = GetESP() + 0x14
imp_num = ReadDword(imp_num_addr)
print(data[imp_num])
Run()

Breakpoint.add(0x0041945B, imp_dump) # can be any address really.
Run()

`

AssembleEx can't handle RETN instructions

I get the error

<b>Traceback (most recent call last):</b>
<b>  File "Z:\raywang\SNAP~E08\release\x32\plugins\x64dbgpy\mona.py", line 18092, in main</b>
<b>    commands[command].parseProc(opts)</b>
<b>  File "Z:\raywang\SNAP~E08\release\x32\plugins\x64dbgpy\mona.py", line 11571, in procROP</b>
<b>    findROPGADGETS(modulecriteria,criteria,endings,maxoffset,depth,split,thedistance,fast,mode)</b>
<b>  File "Z:\raywang\SNAP~E08\release\x32\plugins\x64dbgpy\mona.py", line 6305, in findROPGADGETS</b>
<b>    found_opcodes = searchInModule(search,thismodule,criteria)</b>
<b>  File "Z:\raywang\SNAP~E08\release\x32\plugins\x64dbgpy\mona.py", line 5284, in searchInModule</b>
<b>    return searchInRange(sequences, start, end, criteria)</b>
<b>  File "Z:\raywang\SNAP~E08\release\x32\plugins\x64dbgpy\mona.py", line 5206, in searchInRange</b>
<b>    buf = dbg.assemble(seq)</b>
<b>  File "Z:\raywang\SNAP~E08\release\x32\plugins\x64dbgpy\x64dbgpylib.py", line 1285, in assemble</b>
<b>    res = script.assembler.AssembleEx(address, line)</b>
<b>  File "Z:\raywang\SNAP~E08\release\x32\plugins\x64dbgpy\x64dbgpy\pluginsdk\_scriptapi\assembler.py", line 20, in AssembleEx</b>
<b>    raise Exception(error.value)</b>
<b>Exception: invalid instruction</b>

on a RETN instruction.

Callbacks are not thread safe

Hello,
Callbacks registered there https://github.com/x64dbg/x64dbgpy/blob/v25/py.cpp#L810 are not thread safe and will produce random memory corruptions if an user script is running at the same time. We can't run python from two different threads at the exact same time.

Trigger the random corruption:
Dummy program to debug:
int crash(int a,int b) { int sum = 0; for (int i = 0; i < 0xFFFFFF; i++) sum += a + b; return sum; }

Dummy script:

`import x64dbgpy

def loop():
print("inside loop")
x64dbgpy.pluginsdk.Run()

def outloop():
print("loop finished")
x64dbgpy.pluginsdk.Run()

x64dbgpy.Breakpoint.add(0x140001036,loop)
x64dbgpy.Breakpoint.add(0x140001048,outloop)
x64dbgpy.pluginsdk.Run()`

corruption

Then enjoy random memory corruptions, you may need to run several times to crash or reload binary etc ...

So we need to use GIL lock related functions or maybe use async functions like PyThreadState_SetAsyncExc/Py_AddPendingCall.

Cannot use the "recent" version. ImportError

Hello, I use the python integration since while now and I had upgraded to the last one provided by
I cant use it anymore...

from _x64dbg import *
ImportError: No module named _x64dbg

Did the import syntax changed ? If I revert the plugin folder to the old one , it works well.
Both where fetched here https://ci.appveyor.com/project/mrexodia/x64dbg-python/build/artifacts

The NOT working one from https://github.com/x64dbg/x64dbgpy/tree/v25
4b1c14f36d14c15417885c76273212e3 compiled Tue Jul 10 22:47:15 2018

The working one
32d566001c71295ed0609691ca26dd86 compiled Tue Apr 4 02:33:28 2017

Unable to load x64dbgpy plugin in the latest version of x32dbg

It is unable to load x64dbgpy plugin in the latest version of x32dbg, while it is successfully loaded in x64dbg(64-bit). I'm using "Mar 10 2019" version of x64dbg and Anaconda2(both 32bit and 64bit). The log message is as follows:

[PLUGIN]Failed to load plugin: x64dbgpy.dp32
[PLUGIN, xAnalyzer] Command "xanal" registered!
[PLUGIN, xAnalyzer] Command "xanalremove" registered!
[PLUGIN] xAnalyzer v2 Loaded!

As shown above, another plugin (xAnalyzer in this case) is successfully loaded. Please check it out.

Wrong values in the class Flag

Hi,

I just tried to use the class x64dbgpy.Flag and realized that the values of flags are always incorrect.
Could you please resolve this issues?

Sincerely,
Yen

fixing PYTHONPATH problem [PYTHON] Could not import x64dbgpy mona

Intall python 32 bit & 64 bit in different paths

Delete the PYTHONPATH from your Environment Variables

If you need use immunity debugger make a .bat instead:

set PYTHONPATH=C:\Python27\Lib\site-packages;C:\Python27\Lib;C:\Python27\DLLs
start ImmunityDebugger.exe

Attached image with my PATH env.

dregenvpath

__breakpoints dict becomes empty after the breakpoint hits

#error in while Call_back

i modified the _breakpoints.py class's add( ) to see what was happening

def add(self, address, callback, bp_type=NORMAL, hw_type=EXECUTE):
if bp_type == self.BP_NORMAL:
SetBreakpoint(address)
elif bp_type == self.BP_HARDWARE:
SetHardwareBreakpoint(address, hw_type)
self.__breakpoints[address]['callback'] = callback
self.__breakpoints[address]['type'] = bp_type
print self.__breakpoints[address] #modification to see whether the breakpoint was added at the
specific address

#also i modified the __breakpoint_function

def __breakpoint_function(self, **kwargs):
address = kwargs['addr']
print self.__breakpoints[address] #modification to see whether the breakpoint exits after
if address in self.__breakpoints:
if not (kwargs['enabled'] and kwargs['active']):
return
self.__breakpoints[address]'callback'

#when i run the program below i get the below error
{'callback': <function call_back at 0x056B7E70>, 'type': 1} #results of print from add()
{} #results of print from __breakpoint_function
[PYTHON] Could not use breakpoint function.
Traceback (most recent call last):
File "C:\tools\SNAPSH~1\release\x32\plugins\x64dbgpy\x64dbgpy__breakpoints.py", line 39, in __breakpoint_function
self.__breakpoints[address]'callback'
KeyError: 'callback'

Could You Please tell me why is this happening

the rip pointer is not updated

from x64dbgpy.pluginsdk._scriptapi import *
from x64dbgpy.__events import *
from x64dbgpy.__breakpoints import *
from x64dbgpy.__events import *

def is_debugger_present_callback():
	print hex(register.GetRIP())
	x64dbg.DbgCmdExec("rtr")
	print hex(register.GetRIP())

e=Event()
b=Breakpoint(e)
address = RemoteGetProcAddress('kernel32','CreateFileW')
b.add(address,is_debugger_present_callback)
b.enable()


The output here is:
0x779c0d10
0x779c0d10
(i.e the same rip)

Is there an API to retrieve a list of intermodular calls?

Hi,

is there a possibility to retrieve a list of all the intermodular calls? I just found the x64dbg command named "modcallfind", but unfortunately, this command only gets me the number of calls found, not the values itself as they will be listed in the x64 GUI via Search for > Current Region > Intermodular Calls.

fix pip command

I did some hacks with the PYTHONHOME but now the pip command is broken:

Traceback (most recent call last):
  File "C:\PYTHON~3\lib\logging\__init__.py", line 874, in emit
You are using pip version 7.1.2, however version 8.1.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
[PYTHON] Could not use x64dbg_pip function.
Traceback (most recent call last):
  File "C:\CODEBL~1\x64dbg\bin\x64\plugins\x64dbg_python\utils.py", line 83, in x64dbg_pip
    return pip.main(args=arg_list[1:])
  File "C:\PYTHON~3\lib\site-packages\pip\__init__.py", line 217, in main
    return command.main(cmd_args)
  File "C:\PYTHON~3\lib\site-packages\pip\basecommand.py", line 237, in main
    logger.critical('Exception:', exc_info=True)
  File "C:\PYTHON~3\lib\logging\__init__.py", line 1204, in critical
    self._log(CRITICAL, msg, args, **kwargs)
  File "C:\PYTHON~3\lib\logging\__init__.py", line 1278, in _log
    self.handle(record)
  File "C:\PYTHON~3\lib\logging\__init__.py", line 1288, in handle
    self.callHandlers(record)
  File "C:\PYTHON~3\lib\logging\__init__.py", line 1328, in callHandlers
    hdlr.handle(record)
  File "C:\PYTHON~3\lib\logging\__init__.py", line 751, in handle
    self.emit(record)
  File "C:\PYTHON~3\lib\logging\__init__.py", line 881, in emit
    self.handleError(record)
  File "C:\PYTHON~3\lib\logging\__init__.py", line 804, in handleError
    None, sys.stderr)
  File "C:\PYTHON~3\\lib\traceback.py", line 125, in print_exception
    print_tb(tb, limit, file)
  File "C:\PYTHON~3\\lib\traceback.py", line 70, in print_tb
    if line: _print(file, '    ' + line.strip())
  File "C:\PYTHON~3\\lib\traceback.py", line 13, in _print
    file.write(str+terminator)
  File "C:\CODEBL~1\x64dbg\bin\x64\plugins\x64dbg_python\hooks.py", line 43, in write
    self.callback(text)
  File "C:\CODEBL~1\x64dbg\bin\x64\plugins\x64dbg_python\pluginsdk\_plugins.py", line 5, in _plugin_logprintf

Using mona with x64dbg

I am trying to use mona with x64dbg. I installed the files as instructed.

[PYTHON] Found valid PythonHome in the plugin settings!
[PYTHON] PythonHome: "c:\Program Files\Python\Python27\"
C:\x64dbg\release\x32\plugins\x64dbgpy
[PYTHON] Could not import x64dbgpy.
[PLUGIN] x64dbgpy v1 Loaded!
...
[PYTHON] Executing autorun file: "clean_mona.py".
[PYTHON] Exception...

If I try to capture the exception via:

import sys
try:

	if 'mona' in sys.modules:
	    reload(mona)
	    reload(mona.dbglib)
	    reload(mona.dbglib.pykd)
	else:
	    import mona

except Exception as e: print(e)

I get:

...
[PYTHON] Executing autorun file: "clean_mona.py".
[PYTHON] Execution is done!
...

The mona.mona("help") command doesn't work, as expected.
I can see the x64dbgpy option in the menu, but I am not sure why this failed "Could not import x64dbgpy". Does x64dbg need different installations of Python for 32 and 64 bits?

NOTE: On the 64-bit version I get a:

Loading plugins...
[PLUGIN] Failed to load plugin: x64dbgpy.dp64

It occur Access Violation (that access Memory address 0x0)

Hi.

I want to check debug that ready.
So I run time.sleep(1) loop.
as you know title, it occur access violation :(

python script here.

while BaseFromName("kernel32.dll") == 0:
	time.sleep(1)

access violation1
access violation2

is there any function for waiting debugger?

Unable to change x64dbg.ini Python home

I try to point the pythonhome to another Python install folder, but my changes are overridden on next x64dbg restart.

RIght now, I'm being forced to install python in C:\Python27?

Breakpoint list

Is there a way to access all breakpoints similar to GetList for labels?
BPMAP* does not do the job, as there is no way to increment a pointer in Python.

about get string

Maybe these two functions can be put into library functions. I'm not sure where to put them.

import scriptapi


def get_ansi_str(addr):
    final_str = ''
    i = 0
    while True:
        c = scriptapi.Memory.read(addr+i, 1)
        if c == '\x00':
            break
        final_str += c
        i += 1
    return final_str


def get_wide_str(addr):
    final_str = ''
    i = 0
    while True:
        c = scriptapi.Memory.read(addr+i, 2)
        if c == '\x00\x00':
            break
        final_str += c
        i += 2
    return final_str

An improvement idea for BPMAP() and MEMMAP()

Hi @mrexodia ,
would you accept this patch?

diff -u bridgemain.i.orig bridgemain.i
--- bridgemain.i.orig	2019-09-04 03:15:23.000000000 +0900
+++ bridgemain.i	2019-11-16 01:29:04.902831000 +0900
@@ -30,6 +30,54 @@
 }
 %}
 
+%inline %{
+typedef struct
+{
+    duint BaseAddress;
+    duint AllocationBase;
+    DWORD AllocationProtect;
+    duint RegionSize;
+    DWORD State;
+    DWORD Protect;
+    DWORD Type;
+} PY_MEMORY_BASIC_INFORMATION;
+
+//Debugger structs
+typedef struct
+{
+    PY_MEMORY_BASIC_INFORMATION mbi;
+    char info[MAX_MODULE_SIZE];
+} PY_MEMPAGE;
+%}
+
+%template(MemPageVector) std::vector<PY_MEMPAGE>;
+
+%inline %{
+std::vector<PY_MEMPAGE> GetMemPageList(MEMMAP* mm)
+{
+    std::vector<PY_MEMPAGE> vec(
+        (PY_MEMPAGE *) mm->page,
+        (PY_MEMPAGE *) mm->page + mm->count
+    );
+    BridgeFree(mm->page);
+    return vec;
+}
+%}
+
+%template(BpVector) std::vector<BRIDGEBP>;
+
+%inline %{
+std::vector<BRIDGEBP> GetBpList(BPMAP* bm)
+{
+    std::vector<BRIDGEBP> vec(
+        bm->bp,
+        bm->bp + bm->count
+    );
+    BridgeFree(bm->bp);
+    return vec;
+}
+%}
+
 %include <windows.i>
 #define DECLSPEC_ALIGN(x) __declspec(align(x))
 %include "..\pluginsdk\bridgemain.h"

Then, we can access each breakpoint record and memory section with this script like.

import x64dbgpy

bm = x64dbgpy.pluginsdk.x64dbg.BPMAP()
x64dbgpy.pluginsdk.x64dbg.DbgGetBpList(x64dbgpy.pluginsdk.x64dbg.bp_memory, bm)
if bm.bp is not None:
    for bp in x64dbgpy.pluginsdk.x64dbg.GetBpList(bm):
        print("%x: %s, %x, %d, %x, %x" % (bp.addr, bp.mod, bp.active, bp.type, bp.hitCount, bp.slot))

mm = x64dbgpy.pluginsdk.x64dbg.MEMMAP()
x64dbgpy.pluginsdk.x64dbg.DbgMemMap(mm)
for mp in x64dbgpy.pluginsdk.x64dbg.GetMemPageList(mm):
    print("%x: %x, %x, %x, %x, %x, %x, %s" % (mp.mbi.BaseAddress, mp.mbi.RegionSize, mp.mbi.Protect, mp.mbi.AllocationBase, mp.mbi.AllocationProtect, mp.mbi.State, mp.mbi.Type, mp.info))

How do you use DbgMemFindBaseAddr(duint addr, duint* size) ??

Hello

I try to get the base address and the len of a allocated segment for a given offset.

I don't known how to create the duint pointer required in second argument in python.
I have try to use Ctype.

            address = 0x400000
            slen = 0
            slen_p = c_void_p(slen)
            print DbgMemFindBaseAddr(address, slen_p)
            print slen

But

Traceback (most recent call last):
  File "C:\PROGRA~1\odbg\release\x32\plugins\x64dbgpy\x64dbgpy\__breakpoints.py", line 42, in __breakpoint_function
    **{key: value for key, value in kwargs.iteritems() if key in arg_keys}
  File "C:\Users\azerty\Desktop\UNPACK~1.PY", line 58, in bpcallback
    print DbgMemFindBaseAddr(address, slen_p)
TypeError: in method 'DbgMemFindBaseAddr', argument 2 of type 'duint *'

Anyone knows ?

how to access all element of array in another struct?

I have a script which get instruction place on EIP

ins = pluginsdk.x64dbg.DISASM_INSTR()
pluginsdk.x64dbg.DbgDisasmAt(Register.EIP, ins)

ins has an array field name arg,and arg has 3 element.
I can only access first element of arg.
there is no idea how to aceess other element of arg

typedef struct
{
DISASM_ARGTYPE type; //normal/memory
SEGMENTREG segment;
char mnemonic[64];
duint constant; //constant in the instruction (imm/disp)
duint value; //equal to constant or equal to the register value
duint memvalue; //memsize:[value]
} DISASM_ARG;

typedef struct
{
char instruction[64];
DISASM_INSTRTYPE type;
int argcount;
int instr_size;
DISASM_ARG arg[3];
} DISASM_INSTR;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.