1
0
mirror of synced 2024-11-23 23:31:02 +01:00
ImHex/plugins
descawed 6d14b3f6bd
Fix process memory provider on Linux (#1933)
### Problem description
The process memory provider currently doesn't function correctly on
Linux due to incorrect handling of the special procfs file
`/proc/<pid>/maps`. I don't know if some of this behavior could vary by
distro and/or kernel version, but I've observed the following issues in
my Ubuntu 24.04 environment.

- The current code in master calls `file.readString()` which attempts to
determine the size of the file by [seeking to the
end](https://github.com/WerWolv/libwolv/blob/master/libs/io/source/io/file_unix.cpp#L148).
However, procfs files don't have a defined size, so this fails with a
return of -1. libwolv [interprets this as the file size and attempts to
allocate an enormous
buffer](https://github.com/WerWolv/libwolv/blob/master/libs/io/source/io/file.cpp#L30),
which results in an exception, so ultimately the process memory provider
is unusable on the current code.
- The previous version of the code that went out in 1.35.4 was calling
`readString` with a fixed maximum size of `0xF'FFFF`. This avoids the
seek issue, but when working with special files, a single `read` call
isn't guaranteed to read the requested number of bytes even if that many
bytes are available. In practice, on my machine, this call only ever
reads the first few dozen lines of the file. So the feature works in
this version, but it's unable to see the vast majority of the process'
address space.
- On a more minor note, on rows in the `maps` file that have a filename,
the filenames are visually aligned by padding spaces between the inode
column and filename column. ImHex includes these spaces as part of the
filename, resulting in most of the path being pushed out of the visible
area of the window.

### Implementation description

- To ensure the entire `maps` file is read, I've changed the code to
read from the file in a loop until we stop getting data. I've also set a
fixed limit on the maximum number of bytes to read in one go to avoid
issues with trying to determine the file size.
- I've added a `trim` call to remove any padding around the filename.

### Screenshots
Exception in `file.readString()` in current code (for some reason this
also causes the window to become transparent):

![mem_regions_exception](https://github.com/user-attachments/assets/ac9f472b-3d60-446d-be9c-b028b041e547)

Abridged memory region list in 1.35.4:

![mem_regions_truncated](https://github.com/user-attachments/assets/44e60b23-49f8-41b9-a56b-54cb5c82ee72)

Complete memory region list after this PR:

![mem_regions_working](https://github.com/user-attachments/assets/bdb42dc6-bcd3-42b1-b605-a233b98e8d2e)

### Additional things
I was focused on fixing this ImHex feature here, but I wonder if some of
this should be addressed in libwolv. Maybe `readBuffer` in file_unix.cpp
should read in a loop until it has the requested number of bytes or
encounters EOF/error?

---------

Co-authored-by: Justus Garbe <55301990+jumanji144@users.noreply.github.com>
2024-11-07 13:41:04 +01:00
..
builtin Fix process memory provider on Linux (#1933) 2024-11-07 13:41:04 +01:00
decompress fix: LZMA decompressor memory errors (#1873) 2024-09-15 15:20:17 +02:00
diffing lang: Update Chinese (Simplified) translations (#1894) 2024-09-15 15:17:25 +02:00
disassembler fix: Task names not displaying correctly anymore 2024-07-27 14:09:52 +02:00
fonts fix: Crash on exit when using custom font from file (#1815) 2024-07-15 22:22:02 +02:00
hashes fix: Segfault when hashing regions spanning multiple MiBs (#1804) 2024-07-21 20:35:38 +02:00
script_loader lang: Update Chinese (Simplified) translations (#1894) 2024-09-15 15:17:25 +02:00
ui fix: Multiple race conditions with pattern sorting 2024-10-22 16:20:08 +02:00
visualizers fix: Unable to resize 3d-visualizer window in x-direction (#1860) 2024-09-15 15:27:39 +02:00
windows lang: Update Chinese (Simplified) translations (#1894) 2024-09-15 15:17:25 +02:00
yara_rules fix: Task names not displaying correctly anymore 2024-07-27 14:09:52 +02:00