Comments (6)
update: Problem has been solved
I wrote a small piece of code to convert the UTF16 encoding, maybe you can use it in the future too.
I think UTF8 or other encodings are applicable, you only need to replace ('utf-16')
in the code
temp = b''
while pm.read_bytes(address, 1) != b'\x00':
temp = temp + pm.read_bytes(address, 1)
address += 1
print(temp.decode('utf-16'))
from pymem.
update: Problem has been solved
I wrote a small piece of code to convert the UTF16 encoding, maybe you can use it in the future too.
I think UTF8 or other encodings are applicable, you only need to replace
('utf-16')
in the codetemp = b'' while pm.read_bytes(address, 1) != b'\x00': temp = temp + pm.read_bytes(address, 1) address += 1 print(temp.decode('utf-16'))
this code still have a problem.
result = b''
while pymem_instance.read_bytes(address, 1) != b'\x00':
result = result + pymem_instance.read_bytes(address, 1)
print(result)
address += 1
If the string is all composed of UTF16 is OK. But if the string is composed of a mixture of UTF16 and ASCII, it will still read errors.
The reason for the error is that pymem's read_byte() automatically saves the bytes as ASCII codes, Although what I created in python is a byte variable.
I took two screenshots, the difference is only the CE display text encoding.
from pymem.
Thank you for the reporting, the value is returned as a c_char.
https://docs.python.org/3/library/ctypes.html#ctypes.create_string_buffer
Maybe there should be an alternative that does not break everything within the read_bytes function ?
from pymem.
Thank you for the reporting, the value is returned as a c_char.
https://docs.python.org/3/library/ctypes.html#ctypes.create_string_buffer
Maybe there should be an alternative that does not break everything within the read_bytes function ?
If read_bytes function has been using binary to save data like b'\x07\x86\xF8\x66', then everything will be fine. Because you can use decode('GBK/UTF8/16/LADIN')
to decode into any kind of encoding
from pymem.
update code, now the code can correctly handle UTF16 and ascii mixed encoding
result = ""
address # a memory address
while True:
_temp = pymem.read_bytes(address, 2)
if _temp == b'\x00\x00':
break
else:
try:
_temp = _temp.decode('utf-16')
except UnicodeDecodeError:
logger.warning(f'UTF-16 decode error, replace with empty str')
_temp = ascii(_temp)
finally:
result += _temp
_temp_address += 2
from pymem.
closing this assuming it was fixed by #121
please comment if not
from pymem.
Related Issues (20)
- Optimize write_bytes method HOT 3
- Optimize Memory Reading / Writing using C types HOT 7
- Wrong use of the length of the bytes being written
- Error HOT 1
- `pymem.process.inject_dll` returns local handle instead of remote HOT 5
- `pymem.pattern.scan_pattern_page` throw windows api error, code 299 HOT 8
- is_64_bit potentionally incorrect HOT 2
- There was a problem converting the string to bytes HOT 2
- pymem.exception.WinAPIError: Windows api error, error_code: 87 HOT 4
- Python interpreter injection HOT 2
- switching to github actions HOT 5
- read_string method need a encoding parameter
- add read_unicode_string HOT 3
- inject_python_shellcode(shellcode) not available dict HOT 2
- Suggestion: Change return types to list[int] of pattern_scan_all() HOT 1
- EnumProcessModulesEx - ctypes.ArgumentError: argument 1: OverflowError: int too long to convert HOT 2
- TypeError: 'MockObject' object is not callable HOT 1
- RuntimeError: Could not allocate memory for shellcode in inject_python_shellcode (Python 3.7.16)
- No Module listed HOT 1
- use pyproject.toml HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymem.