question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Negated structure offsets

See original GitHub issue

Is your feature request related to a problem?

When code traverses a multiple linked list data structure, e.g. traversing _PEB_LDR_DATA via InInitializationOrderLinks:

typedef struct _LDR_DATA_TABLE_ENTRY
{
  /* 0x0000 */ struct _LIST_ENTRY InLoadOrderLinks;
  /* 0x0010 */ struct _LIST_ENTRY InMemoryOrderLinks;
  /* 0x0020 */ struct _LIST_ENTRY InInitializationOrderLinks;
  /* 0x0030 */ void* DllBase;
  /* 0x0038 */ void* EntryPoint;
...
} LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY; /* size: 0x00e0 */

You get pointers to the above structure with an offset of 0x10 (offset of InInitializationOrderLinks). If you give this pointer the type struct _LDR_DATA_TABLE_ENTRY all the offsets are obviously wrong.

Describe the solution you’d like

IDA handles this by allowing the user to supply a struct offset, see: https://www.hexblog.com/?p=63 So you hit T on the usage of the struct and define the offset 0x10 and you get your correct types.

Describe alternatives you’ve considered

Currently I copy the old structure and create a new structure with its name prefixed by the offset _0x010 and deleting the first 2 entries in the structure. However, this is:

  • annoying
  • doesn’t work when the pointer uses struct members that are before the offset and hence got removed from the struct by this work around.

Additional context

When working with linked list data structures this features is needed often.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:34
  • Comments:23 (5 by maintainers)

github_iconTop GitHub Comments

16reactions
saidelikecommented, Nov 13, 2019

Even though I agree with all the above, IDA 7.2 actually improved it even more with shifted pointers. See https://www.hex-rays.com/products/ida/support/idadoc/1695.shtml and https://www.hex-rays.com/products/ida/7.2/index.shtml.

Basically, you can define

int *__shifted(mystruct,20) myptr;

where:

        struct mystruct
        {
          char buf[16];
          int dummy;
          int value;            // <- myptr points here
          double fval;
        };

I think having that in Ghidra too would solve all the issues above, and generically.

5reactions
Popax21commented, Aug 6, 2020

For everyone needing this (including me): I’m currently working on implementing shifted pointers, expect a PR in the next few days 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Negated structure offsets - Hex Rays
Negated structure offsets · invert the operand sign by pressing _ (underscore) · select the instruction · press T. delta is 0x14, select...
Read more >
Struct with negative offset in IDA possible
the main purposes of struct is to organize data in a logical container and pass it around. · There is no rule that...
Read more >
How to find the base structure address with negative offsets
Negative offsets are typically used for accessing base class members from a sub-class pointer when multiple inheritance is used.
Read more >
Negative offset in structure
General > The Campus. Negative offset in structure. << < (5/8) > >>. RuiLoureiro: Hey Dave, we have more things to do :biggrin:...
Read more >
Negative offset sub-segments - IBM
Dec Hex Type Len Name (Dim) Description 0 (0) STRUCTURE * ADRRDAYNEG NEGATIVE RUN DAYS 0 (0) CHARACTER 3 ADRRDAYN(*) RUN DAY OFFSETS
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found