本文目录一览:
python怎么修改某个内存地址的数据
使用ctypes模块调用WriteProcessMemory函数,在创建程序进程后,就可以修改该程序指定内存地址。WriteProcessMemory的函数原型如下所示。
BOOL WriteProcessMemory(
HANDLE hProcess,
LPVOID lpBaseAddress,
LPCVOID lpBuffer,
SIZE_T nSize,
SIZE_T* lpNumberOfBytesWritten
);
其参数含义如下。
· hProcess:要写内存的进程句柄。
· lpBaseAddress:要写的内存起始地址。
· lpBuffer:写入值的地址。
· nSize:写入值的大小。
· lpNumberOfBytesWritten :实际写入的大小。
python代码示例如下:
from ctypes import *
# 定义_PROCESS_INFORMATION结构体
class _PROCESS_INFORMATION(Structure):
_fields_ = [('hProcess', c_void_p),
('hThread', c_void_p),
('dwProcessId', c_ulong),
('dwThreadId', c_ulong)]
# 定义_STARTUPINFO结构体
class _STARTUPINFO(Structure):
_fields_ = [('cb',c_ulong),
('lpReserved', c_char_p),
('lpDesktop', c_char_p),
('lpTitle', c_char_p),
('dwX', c_ulong),
('dwY', c_ulong),
('dwXSize', c_ulong),
('dwYSize', c_ulong),
('dwXCountChars', c_ulong),
('dwYCountChars', c_ulong),
('dwFillAttribute', c_ulong),
('dwFlags', c_ulong),
('wShowWindow', c_ushort),
('cbReserved2', c_ushort),
('lpReserved2', c_char_p),
('hStdInput', c_ulong),
('hStdOutput', c_ulong),
('hStdError', c_ulong)]
NORMAL_PRIORITY_CLASS = 0x00000020 # 定义NORMAL_PRIORITY_CLASS
kernel32 = windll.LoadLibrary("kernel32.dll") # 加载kernel32.dll
CreateProcess = kernel32.CreateProcessA # 获得CreateProcess函数地址
ReadProcessMemory = kernel32.ReadProcessMemory # 获得ReadProcessMemory函数地址
WriteProcessMemory = kernel32.WriteProcessMemory # 获得WriteProcessMemory函数地址
TerminateProcess = kernel32.TerminateProcess
# 声明结构体
ProcessInfo = _PROCESS_INFORMATION()
StartupInfo = _STARTUPINFO()
file = 'ModifyMe.exe' # 要进行修改的文件
address = 0x0040103c # 要修改的内存地址
buffer = c_char_p("_") # 缓冲区地址
bytesRead = c_ulong(0) # 读入的字节数
bufferSize = len(buffer.value) # 缓冲区大小
# 创建进程
if CreateProcess(file, 0, 0, 0, 0, NORMAL_PRIORITY_CLASS, 0, 0, byref(StartupInfo), byref(ProcessInfo)):
# 读取要修改的内存地址,以判断是否是要修改的文件
if ReadProcessMemory(ProcessInfo.hProcess, address, buffer, bufferSize, byref(bytesRead)):
if buffer.value == '\x74':
buffer.value = '\x75' # 修改缓冲区内的值,将其写入内存
# 修改内存
if WriteProcessMemory(ProcessInfo.hProcess, address, buffer, bufferSize, byref(bytesRead)):
print '成功改写内存!'
else:
print '写内存错误!'
else:
print '打开了错误的文件!'
TerminateProcess(ProcessInfo.hProcess,0) # 如果不是要修改的文件,则终止进程
else:
print '读内存错误!'
else:
print '不能创建进程!'
python控件批量赋值
test1,test2控件是在Test列表里面?是要把每个控件的变量设置文本的内容?即exec("self.ui.test1.setText("test1")")和("self.ui.test2.setText("test2")")??如果是这样的话可以使用这样写
for i in range(len(Test)):
exec("self.ui.%s.setText('%s')"%(Test[i],Test[i]))
或者不用索引
for i in Test:
exec("self.ui.%s.setText('%s')"%(i,i))
希望有帮助。。。。
python中怎么批量修改字典中values值
for dic_key in dic:
dic[dic_key] = dataframe的values值
就是一个拿出字典的Value赋值的过程。入门级的哟。