0

I am currently trying to XOR 2 IntPtr's but I struggle with it.

My Code:

IntPtr Ptr = IntPtr.Add(Memory.Engine, signatures.model_ambient_min) - 0x2c;
IntPtr xored = (IntPtr)0.5 ^ Ptr;

XOR doesn't seem to be possible with IntPtr's

I want to translate this:

DWORD thisPtr = (int)(dwEngineBase +  modelAmbientMin - 0x2c);
DWORD xored = *(DWORD*)&brightness ^ thisPtr;

to C#

Dmitry
  • 13,797
  • 6
  • 32
  • 48
FuseFire
  • 1
  • 2
  • 2
    What isn't working? What is your desired result? – Retired Ninja Apr 25 '20 at 15:06
  • It's not possible with IntPtr's as it seems. – FuseFire Apr 25 '20 at 15:07
  • 4
    What would XORing two pointers mean? – AKX Apr 25 '20 at 15:10
  • @FuseFire You can use the `+` and `-` operators, but why do you want to XOR the pointers/addresses? – Progman Apr 25 '20 at 15:10
  • Oh I might be mistaken. I want to translate this: ```DWORD thisPtr = (int)(dwEngineBase + modelAmbientMin - 0x2c); DWORD xored = *(DWORD*)&brightness ^ thisPtr;``` to C# – FuseFire Apr 25 '20 at 15:11
  • @FuseFire Please [edit] your question to include the original source code and the current new source code you have in C#. Also add the source of the original source code and explain what you are trying to do. – Progman Apr 25 '20 at 15:15
  • 2
    you're XORing the deferenced value, not the pointer itself – phuclv Apr 25 '20 at 15:28
  • `DWORD` is `int`, not `IntPtr`. Translating the `*(DWORD*)&brightness` requires knowledge about what `brightness` is and why its address is casted to `DWORD*` before it's dereferenced. `0.5` that you are using could not be a result of the dereferencing because it's not a valid `DWORD` value. – GSerg Apr 25 '20 at 15:36
  • brightness is a float value – FuseFire Apr 25 '20 at 15:48
  • So `brightness` is [interpreted as `int`](https://stackoverflow.com/q/173133/11683), and the result of that is xored with `thisPtr`, which in turn is simply `Memory.Engine + signatures.model_ambient_min - 0x2c`. – GSerg Apr 25 '20 at 15:52

0 Answers0