Overview
mem_viewer is a Rust crate that provides a macro view_mem! to view the memory content of an arbitrary variable. It supports viewing memory content of different data types including integers, floating-point numbers, strings, pointers, vectors, boxed variables, and structs.
Usage
Add the following line to your Cargo.toml file:
[]
= "0.2.4"
Then, in your Rust code, you can use the view_mem! macro to view the memory content of a variable. Here's an example:
use *;
let my_var: u16 = 69;
view_mem!;
This will print the memory content of my_var to the console.
Example Output
Name: my_var
Type: u16
Addr: 000000719ddfdce6
Size: 2 bytes
Address | Hex | Dec | Bin | ASCII
-------------------Memory Content---------------
000000719ddfdce6 | 45 | 069 | 01000101 | E
000000719ddfdce7 | 00 | 000 | 00000000 | NUL
Read more for the macro usage: https://docs.rs/mem_viewer/latest/mem_viewer/macro.view_mem.html
Safe Usage
For safe mode, you can use the safe_view_mem! macro to view the memory content of a variable. Here's an example:
use *;
let my_var: u16 = 69;
safe_view_mem!;
Example Safe Output
Name : &my_var
Type : &u16
Addr : 000000719ddfdce6
Size : 8 bytes
Container Ptr: 00000260c1266610
Container Len: 2
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
00000260c1266610 | 45 | 069 | 01000101 | E
00000260c1266611 | 00 | 000 | 00000000 | NUL
Read more for safe usage: https://docs.rs/mem_viewer/latest/mem_viewer/macro.safe_view_mem.html
License
This crate is licensed under the MIT License.
Contributing
Contributions are welcome! If you find any issues or have any suggestions, please open an issue or submit a pull request on GitHub.
Unit Test Report
Code Test:
Output Test:
running 8 tests
test tests::ptr_viewer ... ok
test tests::box_viewer ... ok
test tests::f32_viewer ... ok
test tests::str_viewer ... ok
test tests::struct_viewer ... ok
test tests::u16_viewer ... ok
test tests::vec_of_box_viewer ... ok
test tests::vec_viewer ... ok
successes:
---- tests::ptr_viewer stdout ----
This should print the memory of a pointer.
Currently pointer type is not supported by safe view memory.
Name: my_ptr
Type: *const u8
Addr: 00000034619feb00
Size: 8 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
00000034619feb00 | f8 | 248 | 11111000 | ...
00000034619feb01 | 2f | 047 | 00101111 | /
00000034619feb02 | a6 | 166 | 10100110 | ...
00000034619feb03 | 20 | 032 | 00100000 | SPC
00000034619feb04 | f6 | 246 | 11110110 | ...
00000034619feb05 | 7f | 127 | 01111111 | DEL
00000034619feb06 | 00 | 000 | 00000000 | NUL
00000034619feb07 | 00 | 000 | 00000000 | NUL
Name: *my_ptr
Type: u8
Addr: 00007ff620a62ff8
Size: 1 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
00007ff620a62ff8 | 45 | 069 | 01000101 | E
---- tests::box_viewer stdout ----
This should print the memory address of the box and the memory of its value.
Name : &my_box
Type : &alloc::boxed::Box<u8>
Addr : 00000034615fdfd8
Size : 8 bytes
Container Ptr: 000001e2998cb200
Container Len: 1
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
000001e2998cb200 | 45 | 069 | 01000101 | E
Name: &my_box
Type: &alloc::boxed::Box<u8>
Addr: 00000034615fd968
Size: 8 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
00000034615fda50 | c8 | 200 | 11001000 | ...
00000034615fda51 | d8 | 216 | 11011000 | ...
00000034615fda52 | 5f | 095 | 01011111 | _
00000034615fda53 | 61 | 097 | 01100001 | a
00000034615fda54 | 34 | 052 | 00110100 | 4
00000034615fda55 | 00 | 000 | 00000000 | NUL
00000034615fda56 | 00 | 000 | 00000000 | NUL
00000034615fda57 | 00 | 000 | 00000000 | NUL
Name: my_box
Type: alloc::boxed::Box<u8>
Addr: 00000034615fd8c8
Size: 8 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
00000034615fd8c8 | 00 | 000 | 00000000 | NUL
00000034615fd8c9 | b3 | 179 | 10110011 | ...
00000034615fd8ca | 8c | 140 | 10001100 | ...
00000034615fd8cb | 99 | 153 | 10011001 | ...
00000034615fd8cc | e2 | 226 | 11100010 | ...
00000034615fd8cd | 01 | 001 | 00000001 | SOH
00000034615fd8ce | 00 | 000 | 00000000 | NUL
00000034615fd8cf | 00 | 000 | 00000000 | NUL
Name: *my_box
Type: u8
Addr: 000001e2998cb300
Size: 1 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
000001e2998cb300 | 45 | 069 | 01000101 | E
---- tests::f32_viewer stdout ----
This should print the memory of pi in IEEE 754 representation, which is 0x4048f5c3.
Name: my_f32
Type: f32
Addr: 00000034617fdf14
Size: 4 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
00000034617fdf14 | c3 | 195 | 11000011 | ...
00000034617fdf15 | f5 | 245 | 11110101 | ...
00000034617fdf16 | 48 | 072 | 01001000 | H
00000034617fdf17 | 40 | 064 | 01000000 | @
Name : &my_f32
Type : &f32
Addr : 00000034617fdf14
Size : 8 bytes
Container Ptr: 000001e2998d1c40
Container Len: 4
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
000001e2998d1c40 | c3 | 195 | 11000011 | ...
000001e2998d1c41 | f5 | 245 | 11110101 | ...
000001e2998d1c42 | 48 | 072 | 01001000 | H
000001e2998d1c43 | 40 | 064 | 01000000 | @
---- tests::str_viewer stdout ----
This should print the memory of 'Hello' and its address.
Name: my_str
Type: &str
Addr: 0000003461bfcaf8
Size: 16 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
0000003461bfcaf8 | 98 | 152 | 10011000 | ...
0000003461bfcaf9 | 2f | 047 | 00101111 | /
0000003461bfcafa | a6 | 166 | 10100110 | ...
0000003461bfcafb | 20 | 032 | 00100000 | SPC
0000003461bfcafc | f6 | 246 | 11110110 | ...
0000003461bfcafd | 7f | 127 | 01111111 | DEL
0000003461bfcafe | 00 | 000 | 00000000 | NUL
0000003461bfcaff | 00 | 000 | 00000000 | NUL
0000003461bfcb00 | 05 | 005 | 00000101 | ENQ
0000003461bfcb01 | 00 | 000 | 00000000 | NUL
0000003461bfcb02 | 00 | 000 | 00000000 | NUL
0000003461bfcb03 | 00 | 000 | 00000000 | NUL
0000003461bfcb04 | 00 | 000 | 00000000 | NUL
0000003461bfcb05 | 00 | 000 | 00000000 | NUL
0000003461bfcb06 | 00 | 000 | 00000000 | NUL
0000003461bfcb07 | 00 | 000 | 00000000 | NUL
Name: *my_str
Type: str
Addr: 00007ff620a62f98
Size: 5 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
00007ff620a62f98 | 48 | 072 | 01001000 | H
00007ff620a62f99 | 65 | 101 | 01100101 | e
00007ff620a62f9a | 6c | 108 | 01101100 | l
00007ff620a62f9b | 6c | 108 | 01101100 | l
00007ff620a62f9c | 6f | 111 | 01101111 | o
Name : &my_str
Type : &&str
Addr : 0000003461bfcaf8
Size : 8 bytes
Container Ptr: 000001e2998d1c30
Container Len: 5
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
000001e2998d1c30 | 48 | 072 | 01001000 | H
000001e2998d1c31 | 65 | 101 | 01100101 | e
000001e2998d1c32 | 6c | 108 | 01101100 | l
000001e2998d1c33 | 6c | 108 | 01101100 | l
000001e2998d1c34 | 6f | 111 | 01101111 | o
Name : my_str
Type : &str
Addr : 00007ff620a62f98
Size : 16 bytes
Container Ptr: 000001e2998d1c40
Container Len: 5
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
000001e2998d1c40 | 48 | 072 | 01001000 | H
000001e2998d1c41 | 65 | 101 | 01100101 | e
000001e2998d1c42 | 6c | 108 | 01101100 | l
000001e2998d1c43 | 6c | 108 | 01101100 | l
000001e2998d1c44 | 6f | 111 | 01101111 | o
---- tests::struct_viewer stdout ----
This should print the memory address of the struct and the memory of its fields.
Name : &my_serialized_struct
Type : &mem_viewer::tests::MySerializedStruct
Addr : 0000003461dfe168
Size : 8 bytes
Container Ptr: 000001e2998cb350
Container Len: 7
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
000001e2998cb350 | 45 | 069 | 01000101 | E
000001e2998cb351 | ff | 255 | 11111111 | ...
000001e2998cb352 | 00 | 000 | 00000000 | NUL
000001e2998cb353 | 46 | 070 | 01000110 | F
000001e2998cb354 | 00 | 000 | 00000000 | NUL
000001e2998cb355 | 00 | 000 | 00000000 | NUL
000001e2998cb356 | 00 | 000 | 00000000 | NUL
Name: &my_struct
Type: &mem_viewer::tests::MyStruct
Addr: 0000003461dfdcb8
Size: 8 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
0000003461dfdda0 | 10 | 016 | 00010000 | DLE
0000003461dfdda1 | dc | 220 | 11011100 | ...
0000003461dfdda2 | df | 223 | 11011111 | ...
0000003461dfdda3 | 61 | 097 | 01100001 | a
0000003461dfdda4 | 34 | 052 | 00110100 | 4
0000003461dfdda5 | 00 | 000 | 00000000 | NUL
0000003461dfdda6 | 00 | 000 | 00000000 | NUL
0000003461dfdda7 | 00 | 000 | 00000000 | NUL
Name: my_struct
Type: mem_viewer::tests::MyStruct
Addr: 0000003461dfdc10
Size: 8 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
0000003461dfdc10 | 46 | 070 | 01000110 | F
0000003461dfdc11 | 00 | 000 | 00000000 | NUL
0000003461dfdc12 | 00 | 000 | 00000000 | NUL
0000003461dfdc13 | 00 | 000 | 00000000 | NUL
0000003461dfdc14 | ff | 255 | 11111111 | ...
0000003461dfdc15 | 00 | 000 | 00000000 | NUL
0000003461dfdc16 | 45 | 069 | 01000101 | E
0000003461dfdc17 | 00 | 000 | 00000000 | NUL
---- tests::u16_viewer stdout ----
This should print the memory of the holy number 69.
Name: my_u16
Type: u16
Addr: 0000003461ffe006
Size: 2 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
0000003461ffe006 | 45 | 069 | 01000101 | E
0000003461ffe007 | 00 | 000 | 00000000 | NUL
Name : &my_u16
Type : &u16
Addr : 0000003461ffe006
Size : 8 bytes
Container Ptr: 000001e2998cb220
Container Len: 2
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
000001e2998cb220 | 45 | 069 | 01000101 | E
000001e2998cb221 | 00 | 000 | 00000000 | NUL
---- tests::vec_of_box_viewer stdout ----
This should print the memory address of the vector of boxes and the memory of its elements.
Name : &my_vec_of_box
Type : &alloc::vec::Vec<alloc::boxed::Box<u8>>
Addr : 00000034615fe530
Size : 8 bytes
Container Ptr: 000001e2998d1c00
Container Len: 5
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
000001e2998d1c00 | 45 | 069 | 01000101 | E
000001e2998d1c01 | ff | 255 | 11111111 | ...
000001e2998d1c02 | fe | 254 | 11111110 | ...
000001e2998d1c03 | fd | 253 | 11111101 | ...
000001e2998d1c04 | 46 | 070 | 01000110 | F
Name: my_vec_of_box
Type: alloc::vec::Vec<alloc::boxed::Box<u8>>
Addr: 00000034615ff0d0
Size: 24 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
00000034615ff0d0 | 05 | 005 | 00000101 | ENQ
00000034615ff0d1 | 00 | 000 | 00000000 | NUL
00000034615ff0d2 | 00 | 000 | 00000000 | NUL
00000034615ff0d3 | 00 | 000 | 00000000 | NUL
00000034615ff0d4 | 00 | 000 | 00000000 | NUL
00000034615ff0d5 | 00 | 000 | 00000000 | NUL
00000034615ff0d6 | 00 | 000 | 00000000 | NUL
00000034615ff0d7 | 00 | 000 | 00000000 | NUL
00000034615ff0d8 | 50 | 080 | 01010000 | P
00000034615ff0d9 | 85 | 133 | 10000101 | ...
00000034615ff0da | 8c | 140 | 10001100 | ...
00000034615ff0db | 99 | 153 | 10011001 | ...
00000034615ff0dc | e2 | 226 | 11100010 | ...
00000034615ff0dd | 01 | 001 | 00000001 | SOH
00000034615ff0de | 00 | 000 | 00000000 | NUL
00000034615ff0df | 00 | 000 | 00000000 | NUL
00000034615ff0e0 | 05 | 005 | 00000101 | ENQ
00000034615ff0e1 | 00 | 000 | 00000000 | NUL
00000034615ff0e2 | 00 | 000 | 00000000 | NUL
00000034615ff0e3 | 00 | 000 | 00000000 | NUL
00000034615ff0e4 | 00 | 000 | 00000000 | NUL
00000034615ff0e5 | 00 | 000 | 00000000 | NUL
00000034615ff0e6 | 00 | 000 | 00000000 | NUL
00000034615ff0e7 | 00 | 000 | 00000000 | NUL
Name: *my_vec_of_box
Type: [alloc::boxed::Box<u8>]
Addr: 000001e2998c8550
Size: 40 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
000001e2998c8550 | 90 | 144 | 10010000 | ...
000001e2998c8551 | 1c | 028 | 00011100 | FS
000001e2998c8552 | 8d | 141 | 10001101 | ...
000001e2998c8553 | 99 | 153 | 10011001 | ...
000001e2998c8554 | e2 | 226 | 11100010 | ...
000001e2998c8555 | 01 | 001 | 00000001 | SOH
000001e2998c8556 | 00 | 000 | 00000000 | NUL
000001e2998c8557 | 00 | 000 | 00000000 | NUL
000001e2998c8558 | 80 | 128 | 10000000 | ...
000001e2998c8559 | 1c | 028 | 00011100 | FS
000001e2998c855a | 8d | 141 | 10001101 | ...
000001e2998c855b | 99 | 153 | 10011001 | ...
000001e2998c855c | e2 | 226 | 11100010 | ...
000001e2998c855d | 01 | 001 | 00000001 | SOH
000001e2998c855e | 00 | 000 | 00000000 | NUL
000001e2998c855f | 00 | 000 | 00000000 | NUL
000001e2998c8560 | a0 | 160 | 10100000 | ...
000001e2998c8561 | 1c | 028 | 00011100 | FS
000001e2998c8562 | 8d | 141 | 10001101 | ...
000001e2998c8563 | 99 | 153 | 10011001 | ...
000001e2998c8564 | e2 | 226 | 11100010 | ...
000001e2998c8565 | 01 | 001 | 00000001 | SOH
000001e2998c8566 | 00 | 000 | 00000000 | NUL
000001e2998c8567 | 00 | 000 | 00000000 | NUL
000001e2998c8568 | 40 | 064 | 01000000 | @
000001e2998c8569 | 1c | 028 | 00011100 | FS
000001e2998c856a | 8d | 141 | 10001101 | ...
000001e2998c856b | 99 | 153 | 10011001 | ...
000001e2998c856c | e2 | 226 | 11100010 | ...
000001e2998c856d | 01 | 001 | 00000001 | SOH
000001e2998c856e | 00 | 000 | 00000000 | NUL
000001e2998c856f | 00 | 000 | 00000000 | NUL
000001e2998c8570 | 60 | 096 | 01100000 | `
000001e2998c8571 | 1c | 028 | 00011100 | FS
000001e2998c8572 | 8d | 141 | 10001101 | ...
000001e2998c8573 | 99 | 153 | 10011001 | ...
000001e2998c8574 | e2 | 226 | 11100010 | ...
000001e2998c8575 | 01 | 001 | 00000001 | SOH
000001e2998c8576 | 00 | 000 | 00000000 | NUL
000001e2998c8577 | 00 | 000 | 00000000 | NUL
Name: *my_vec_of_box[0]
Type: u8
Addr: 000001e2998d1c90
Size: 1 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
000001e2998d1c90 | 45 | 069 | 01000101 | E
---- tests::vec_viewer stdout ----
This should print the memory address of the vector and the memory of its elements.
Name : &my_vec
Type : &alloc::vec::Vec<u8>
Addr : 00000034615fe508
Size : 8 bytes
Container Ptr: 000001e2998d1c60
Container Len: 5
Address | Hex | Dec | Bin | ASCII
---------------Container Content---------------
000001e2998d1c60 | 45 | 069 | 01000101 | E
000001e2998d1c61 | ff | 255 | 11111111 | ...
000001e2998d1c62 | fe | 254 | 11111110 | ...
000001e2998d1c63 | fd | 253 | 11111101 | ...
000001e2998d1c64 | 46 | 070 | 01000110 | F
Name: my_vec
Type: alloc::vec::Vec<u8>
Addr: 00000034615ff080
Size: 24 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
00000034615ff080 | 05 | 005 | 00000101 | ENQ
00000034615ff081 | 00 | 000 | 00000000 | NUL
00000034615ff082 | 00 | 000 | 00000000 | NUL
00000034615ff083 | 00 | 000 | 00000000 | NUL
00000034615ff084 | 00 | 000 | 00000000 | NUL
00000034615ff085 | 00 | 000 | 00000000 | NUL
00000034615ff086 | 00 | 000 | 00000000 | NUL
00000034615ff087 | 00 | 000 | 00000000 | NUL
00000034615ff088 | 40 | 064 | 01000000 | @
00000034615ff089 | 1c | 028 | 00011100 | FS
00000034615ff08a | 8d | 141 | 10001101 | ...
00000034615ff08b | 99 | 153 | 10011001 | ...
00000034615ff08c | e2 | 226 | 11100010 | ...
00000034615ff08d | 01 | 001 | 00000001 | SOH
00000034615ff08e | 00 | 000 | 00000000 | NUL
00000034615ff08f | 00 | 000 | 00000000 | NUL
00000034615ff090 | 05 | 005 | 00000101 | ENQ
00000034615ff091 | 00 | 000 | 00000000 | NUL
00000034615ff092 | 00 | 000 | 00000000 | NUL
00000034615ff093 | 00 | 000 | 00000000 | NUL
00000034615ff094 | 00 | 000 | 00000000 | NUL
00000034615ff095 | 00 | 000 | 00000000 | NUL
00000034615ff096 | 00 | 000 | 00000000 | NUL
00000034615ff097 | 00 | 000 | 00000000 | NUL
Name: *my_vec
Type: [u8]
Addr: 000001e2998d1c40
Size: 5 bytes
Address | Hex | Dec | Bin | ASCII
-----------------Memory Content-----------------
000001e2998d1c40 | 45 | 069 | 01000101 | E
000001e2998d1c41 | ff | 255 | 11111111 | ...
000001e2998d1c42 | fe | 254 | 11111110 | ...
000001e2998d1c43 | fd | 253 | 11111101 | ...
000001e2998d1c44 | 46 | 070 | 01000110 | F
successes:
tests::box_viewer
tests::f32_viewer
tests::ptr_viewer
tests::str_viewer
tests::struct_viewer
tests::u16_viewer
tests::vec_of_box_viewer
tests::vec_viewer
test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s