capa icon indicating copy to clipboard operation
capa copied to clipboard

dotnet: how to represent getter/setters

Open williballenthin opened this issue 3 years ago • 12 comments

dotnet may emit accessor/mutators (getter/setters) for some fields rather than direct field access. how do we recognize and emit these features?

williballenthin avatar Apr 04 '22 16:04 williballenthin

need concrete example

williballenthin avatar Apr 04 '22 16:04 williballenthin

suspect that getter/setter is identified via method def flag

williballenthin avatar Apr 07 '22 15:04 williballenthin

do we need a few feature for instance property access? do we reuse offset?

e.g.

- property: System.Net.FtpWebResponse.statusCode
- offset: System.Net.FtpWebResponse.statusCode

williballenthin avatar Apr 07 '22 15:04 williballenthin

Screen Shot 2022-04-07 at 10 43 09 AM

mike-hunhoff avatar Apr 07 '22 16:04 mike-hunhoff

for imported classes we may be able to identify getter/setter by signature type; specifically if the signature is of type Property.

Screen Shot 2022-04-07 at 10 58 02 AM

mike-hunhoff avatar Apr 07 '22 17:04 mike-hunhoff

wow getters can have parameters? makes me think we might want to emit both API and property features.

On Apr 7, 2022, at 11:06 AM, Mike Hunhoff @.***> wrote:

 for imported classes we may be able to identify getter/setter by signature type; specifically if the signature is of type Property.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

williballenthin avatar Apr 07 '22 17:04 williballenthin

example:

C#:

ftpRequest.KeepAlive = false;

IL:

IL_0000: callvirt  instance void [System]System.Net.FtpWebRequest::set_KeepAlive(bool)

mike-hunhoff avatar Apr 07 '22 21:04 mike-hunhoff

I like the idea of adding new property and field features. it may also be useful for users to specify whether a property/field is read/written.

detection should be fairly straightforward. non-public fields are accessed via properties, which we can identify using the .NET metadata. public fields, from my understanding, are accessed directly using CIL instructions stfld/stsfld, ldfld/ldflda/ldsfld/ldsflda.

I'm unsure how to represent read/writes to properties/fields if we decide to go that route.

(1) use / notation:

- property/get: System.Net.FtpWebRequest::KeepAlive

(2) use the get_ and set_ nomenclature seen in dnSpy:

- property: System.Net.FtpWebRequest::get_KeepAlive

(3) don't facilitate read/write access:

- property: System.Net.FtpWebRequest::KeepAlive

I lean towards 3 simply because I can't think of an example where it would be useful to specify read/write access.

mike-hunhoff avatar May 05 '22 14:05 mike-hunhoff

do you think its important to differentiate properties from fields?

williballenthin avatar May 05 '22 15:05 williballenthin

No, I think it'd be fine to choose one feature term to represent both. If I were to choose one I'd prefer field or to reuse offset as you suggested.

mike-hunhoff avatar May 05 '22 17:05 mike-hunhoff

I think (3) is sufficient for now. I'm not a fan of the other syntax proposals.

mr-tz avatar May 06 '22 13:05 mr-tz

I've changed my mind and think differentiating between read and write would be useful.

1.

- property/get: System.Net.FtpWebRequest::KeepAlive
- property/set: System.Net.FtpWebRequest::KeepAlive

2.

- property/read: System.Net.FtpWebRequest::KeepAlive
- property/write: System.Net.FtpWebRequest::KeepAlive

3.

- property/r: System.Net.FtpWebRequest::KeepAlive
- property/w: System.Net.FtpWebRequest::KeepAlive

I'm in favor of 2. since it's clear and appears most versatile (across languages/formats).

mr-tz avatar Aug 10 '22 09:08 mr-tz

closed by #1168

mike-hunhoff avatar Sep 16 '22 18:09 mike-hunhoff