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.

  • what is the type of dword_1F4A8A5C? (press Y on it or hover mouse). – Igor Skochinsky Feb 18 '18 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. – Edward Severinsen Feb 18 '18 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 Feb 19 '18 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. – Edward Severinsen Feb 20 '18 at 15:36
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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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