1
0
mirror of synced 2025-01-09 13:11:38 +01:00
ImHex/plugins/builtin/source/content
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
..
data_processor_nodes impr: Run data processor in a worker task 2024-07-11 23:30:54 +02:00
helpers impr: Handle demangling of identifiers without leading underscore 2024-07-11 20:38:22 +02:00
pl_visualizers fix: Multiple issues causing visualizers to crash when used _slightly_ incorrectly 2024-07-10 20:50:58 +02:00
popups/hex_editor fix: Task names not displaying correctly anymore 2024-07-27 14:09:52 +02:00
providers Fix process memory provider on Linux (#1933) 2024-11-07 13:41:04 +01:00
tools feat: Added a quarter precision (8 bits) button to IEEE 745 tool (#1868) 2024-09-15 15:22:35 +02:00
tutorials impr: Code style improvements 2023-12-27 16:33:49 +01:00
views fix: Multiple race conditions with pattern sorting 2024-10-22 16:20:08 +02:00
achievements.cpp fix: Ambiguous conversion to UnlocalizedString 2024-01-21 14:31:19 +01:00
background_services.cpp impr: Fix various issues with runtime-generated language strings 2024-08-03 11:32:17 +02:00
command_line_interface.cpp impr: Handle demangling of identifiers without leading underscore 2024-07-11 20:38:22 +02:00
command_palette_commands.cpp fix: Build issues due to unused variables 2024-01-21 21:39:50 +01:00
communication_interface.cpp refactor: Better interface for the event system 2023-12-08 10:29:44 +01:00
data_formatters.cpp feat: Added CSV, TSV and JSON as export options for Find results (#1673) 2024-06-18 20:57:55 +00:00
data_information_sections.cpp impr: Added data size widget 2024-05-19 10:21:54 +02:00
data_inspector.cpp fix: Misspelling of Endianness (#1609) 2024-03-28 22:25:28 +01:00
data_processor_nodes.cpp refactor: Split data processor nodes in several files (#1419) 2023-11-13 23:36:39 +01:00
data_visualizers.cpp impr: Further optimize ImGui text rendering 2024-06-27 17:09:20 +02:00
events.cpp impr: Make unsaved changes popup behave more like in other applications 2024-04-23 21:02:16 +02:00
file_extraction.cpp fix: Replace old defaults path system with a new one 2024-06-22 10:44:55 +02:00
file_handlers.cpp fix: Replace old defaults path system with a new one 2024-06-22 10:44:55 +02:00
global_actions.cpp impr: Make unsaved changes popup behave more like in other applications 2024-04-23 21:02:16 +02:00
init_tasks.cpp impr: Make all task names properly translatable 2024-07-27 16:29:06 +02:00
main_menu_items.cpp impr: Make all task names properly translatable 2024-07-27 16:29:06 +02:00
minimap_visualizers.cpp impr: Make the highlights minimap visualizer the default 2024-06-26 19:12:20 +02:00
out_of_box_experience.cpp fix: Sub windows being used incorrectly 2024-06-26 19:11:31 +02:00
pl_builtin_functions.cpp impr: Handle demangling of identifiers without leading underscore 2024-07-11 20:38:22 +02:00
pl_pragmas.cpp fix: Multiple race conditions with pattern sorting 2024-10-22 16:20:08 +02:00
pl_visualizers.cpp fix: Multiple issues causing visualizers to crash when used _slightly_ incorrectly 2024-07-10 20:50:58 +02:00
project.cpp fix: Remove accidentally committed test code 2024-06-22 23:03:54 +02:00
providers.cpp fix: Don't try to compile process memory provider into Web build 2024-06-07 20:32:04 +02:00
recent.cpp impr: Make all task names properly translatable 2024-07-27 16:29:06 +02:00
report_generators.cpp impr: Optimize api includes 2023-11-30 11:23:12 +01:00
settings_entries.cpp impr: Fix various issues with runtime-generated language strings 2024-08-03 11:32:17 +02:00
themes.cpp build: Updated ImGui, libfmt and libyara 2024-07-01 22:00:08 +02:00
tools_entries.cpp feat: Added simple HTTP request tool 2024-01-04 00:38:21 +01:00
ui_items.cpp impr: Fix various issues with runtime-generated language strings 2024-08-03 11:32:17 +02:00
views.cpp impr: Allow views to opt out of having their open state saved 2024-05-19 21:51:55 +02:00
welcome_screen.cpp impr: Make all task names properly translatable 2024-07-27 16:29:06 +02:00
window_decoration.cpp fix: Sidebar panels not being resizable anymore properly 2024-07-16 18:15:28 +02:00
workspaces.cpp feat: Allow workspaces to be deleted the same way as layouts 2024-02-28 22:10:48 +01:00