1

While reverse engineering a game using the Hex Rays decompiler I was looking for how an array of NPC's was accessed. I found the array but I don't quite understand the unusual formula for getting the index of the NPC. First an integer is & with 0xFFF then the result is multiplied by 4 to get the index.

Example:

dword_1F4A8A5C[4 * (v3 & 0xFFF)]

I'm really not sure if this is standard or if it's weird output from the Hex Rays decompiler. If anyone has an explanation please let me know. Thanks.

4
  • what is the type of dword_1F4A8A5C? (press Y on it or hover mouse).
    – Igor Skochinsky
    Commented Feb 18, 2018 at 21:35
  • @IgorSkochinsky It's an array of integers. The dll I'm reversing is 32-bit and the element it accesses is the address of the NPC/enemy. Commented Feb 18, 2018 at 22:54
  • It looks like that it is array of structures, where v3 is an index and 0xfff is used to avoid overfflow - I'd suggest that the array was originally defined with size 0x1000. The size of a structure should be 4 dwords.
    – w s
    Commented Feb 19, 2018 at 9:58
  • @ws Okay, after you explained it this makes more since. v3 & 0xFFF doesn't allow anything over 0x999. And I had the misconception that it was an array of pointers to structures. Not an actual array of structures. Thank you, you've helped tremendously. If you would like you can turn it into an answer and I'll accept it. Commented Feb 20, 2018 at 15:36

1 Answer 1

2

It looks like that it is array of structures, where v3 is an index and 0xfff is used to avoid overflow. I'd suggest that the array was originally defined with size 0x1000. The size of a structure should be 4 dwords.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.