mnemonikr / symbolic-pcode

Apache License 2.0
0 stars 0 forks source link

Remove requirement to construct Memory with address spaces #72

Closed mnemonikr closed 8 months ago

mnemonikr commented 1 year ago

It would be simpler to allow reading and writing to arbitrary address spaces. If reading from an address space that's never been provided, clearly no data. This allows returning UndefinedData instead of needing the specialized error UnknownAddressSpace.

If writing to an address space for the first time, create it on demand.

mnemonikr commented 1 year ago

A complication is the load and store functions in the Emulator reference the address space by space id. In order to construct the Address for the VarnodeData we need the AddressSpace. We currently fetch that object using the address spaces passed to Memory at initialization:

https://github.com/mnemonikr/pcode/blob/74c1f64ca2d8ddafea4eed8d9096b7bfd6a569ef/src/emulator.rs#L327

Now arguably to read and write we only need the following:

Now in this special case, we are guaranteed that the address space is not one that requires special handling (e.g. constant address space). But to address that more cleanly, it might make sense to move that special handling outside of Memory entirely.

mnemonikr commented 1 year ago

In addition to the address space id, we also need the address size of the loaded address space. We weren't ensuring this constraint was held previously.

https://github.com/mnemonikr/pcode/blob/9694e9ba6563ce5cc328aa2d97d406a28db0516a/src/emulator.rs#L1028

Faking the address space for load and store seems like a bad idea. The right thing to do would be to either perform a Sleigh query from the emulator to load the Address Space data, or cache the full set of address spaces in the emulator. Which we already do in the emulator, we just pass it directly to the memory module.

We could stop doing that and just store it in the emulator directly instead.

mnemonikr commented 8 months ago

Resolved in #92 . Address spaces are now cached in the Emulator.