最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to mirror a struct that uses a 'std::string' with python ctypes? - Stack Overflow

programmeradmin4浏览0评论

I used to mirror a cpp application struct exactly, in order to 'hack' in some memory and read/access their normally unaccessible values (due to poor API support for some area of their app).

I used to do this kind of technique:

import ctypes 

class AppStructFoo(ctypes.Structure):
        _fields_ = [
            ("next", ctypes.c_void_p),
            ("prev", ctypes.c_void_p),            
            ("name", ctypes.c_char * 64),
            ("identifier", ctypes.c_int32),
            ("flag", ctypes.c_int),
            ("idname", ctypes.c_char * 64),
            ("typeinfo", ctypes.c_void_p),
            ("type_legacy", ctypes.c_int16),
            ("ui_order", ctypes.c_int16),
            ("custom1", ctypes.c_int16),
            ("custom2", ctypes.c_int16), #Goal was to read this int let say..
            #ect..
            ]

node_struct = AppStructFoo.from_address(memory_adress)
print(node_struct.custom2)
>>> 12 #YES! it was working perfectly!!

But, now the application struct that i'm mirroring recently changed it's char name[64]; and char idname[64]; property to a std::string name; type of character chain.

Therefore i wonder if there's a pythonic/ctypes solution to match a std::string memory layout? or perhaps if there is a way to skip it? The string is not boudn to 64 char anymore.. the limit is now unknown.

This std::string element is similar to an unknown obstacle that i cannot seem to bypass in order to reach my objective

Any idea?

发布评论

评论列表(0)

  1. 暂无评论