通过DMA读取指定地址的字符串 - DmaReadString
函数简介
通过 DMA 读取指定地址的字符串。支持多种字符串编码格式和 CE 地址格式。(高级版功能,普通版无法使用)
接口名称
DmaReadString
DLL调用
OLA_STRING_RETURN OLA_CALL_TYPE DmaReadString(int64_t instance, int64_t deviceId, int32_t pid, OLA_STRING_INPUT addr, int32_t type, int32_t len);
参数定义:
instance(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。deviceId(长整型数): 设备IDpid(整型数): 进程 PIDaddr(字符串): 地址,支持 CE 数据格式type(整型数): 字符串类型len(整型数): 读取长度(字节),0 表示自动判定
示例:
// 读取 GBK 字符串(自动判定长度)
const char* str = DmaReadString(instance, deviceId, 1234, "0x400000", 0, 0);
if (str != NULL) {
printf("GBK字符串: %s\n", str);
FreeStringPtr(instance, str);
}
// 读取 Unicode 字符串(指定长度)
const char* str2 = DmaReadString(instance, deviceId, 1234, "0x400010", 1, 32);
if (str2 != NULL) {
printf("Unicode字符串: %s\n", str2);
FreeStringPtr(instance, str2);
}
// 读取 UTF8 字符串
const char* str3 = DmaReadString(instance, deviceId, 1234, "0x400020", 2, 0);
if (str3 != NULL) {
printf("UTF8字符串: %s\n", str3);
FreeStringPtr(instance, str3);
}
// 使用 CE 格式地址读取
const char* str4 = DmaReadString(instance, deviceId, 1234, "[<Game.exe>+1234]+8", 0, 0);
if (str4 != NULL) {
printf("字符串: %s\n", str4);
FreeStringPtr(instance, str4);
}
返回值
字符串:
返回二进制字符串的指针,数据格式为 UTF-8 编码的字符串
注意: 返回的字符串指针需要调用 FreeStringPtr 接口释放内存
参数说明
type(字符串类型):
- 0: GBK 字符串
- 1: Unicode 字符串
- 2: UTF8 字符串
len(长度):
- 0: 自动判定字符串长度(遇到 null 终止符)
0: 指定读取的字节数
addr(地址):
- 支持十六进制格式:
0x400000 - 支持 CE 格式:
[[[<module>+offset1]+offset2]+offset3] - 支持模块相对地址:
<Game.exe>+1234+8+4
应用场景
- 读取游戏中的文本
- 字符串提取
- 内存分析
相关接口
- DmaReadStringAddr - 直接地址读取
- DmaReadData - 读取二进制数据
- DmaFindString - 搜索字符串
