3

I have a JSON class like this:

public class UpdateCheck
{
    public bool UpdatesAvailable { get; set; }
    public string LinkOfNewVersion { get; set; }
}

But the value of UpdatesAvailable and LinkOfNewVersion are null when I confuse my assembly using ConfuserEx :/

I've tried all the following:

Adding the [Obfuscation(Exclude = false, Feature = "-rename")] attribute above my JSON class:

[Obfuscation(Exclude = false, Feature = "-rename")]
public class UpdateCheck
{
    public bool UpdatesAvailable { get; set; }
    public string LinkOfNewVersion { get; set; }
}

Adding the [Serializable] attribute above my JSON class:

[Serializable]
public class UpdateCheck
{
    public bool UpdatesAvailable { get; set; }
    public string LinkOfNewVersion { get; set; }
}

Adding both attributes above my JSON class:

[Serializable]
[Obfuscation(Exclude = false, Feature = "-rename")]
public class UpdateCheck
{
    public bool UpdatesAvailable { get; set; }
    public string LinkOfNewVersion { get; set; }
}

But all what I've tried failed :/

My obfuscation properties:

  <rule pattern="true" preset="maximum" inherit="false">
    <protection id="anti ildasm" />
    <protection id="anti tamper" />
    <protection id="constants" />
    <protection id="ctrl flow" />
    <protection id="anti dump" />
    <protection id="anti debug" />
    <protection id="invalid metadata" />
    <protection id="ref proxy" />
    <protection id="resources" />
    <protection id="typescramble" />
    <protection id="rename" />
  </rule>

And when I remove the "rename" protection from my ConfuserEx config file, my assembly crashes like that: enter image description here

Any help would be appreciated.

Thanks!

TECNO
  • 162
  • 2
  • 3
  • 15
gave
  • 181
  • 13

2 Answers2

5

Try using JsonProperty attributes to set the field names to their fixed values:

public class UpdateCheck
{
    [JsonProperty("UpdatesAvailable")]
    public bool UpdatesAvailable { get; set; }

    [JsonProperty("LinkOfNewVersion")]
    public string LinkOfNewVersion { get; set; }
}
Peter B
  • 22,460
  • 5
  • 32
  • 69
  • Thank you for your time! But unfortunately, I am still getting this crash: https://i.stack.imgur.com/eTVtz.png – gave Sep 13 '18 at 11:04
  • Based on the error you are getting, see if this Q&A helps: [InvalidProgramException / Common Language Runtime detected an invalid program](https://stackoverflow.com/q/23563299/1220550) – Peter B Sep 13 '18 at 11:08
  • 1
    I've disabled the `typescramble` feature of ConfuserEx and now the crash disappeared. Also the JSON is working now! I will accept this solution once I can :-) – gave Sep 13 '18 at 11:17
  • @gave How to disabled the typescramble, I don't see this option at Setting tab – Kien Vu Oct 15 '21 at 15:59
0

You have to specifically remove "name" & "typescramble" options. Using any preset above "None" includes "name" which is the main issue. I use maximum Preset without these two with no issues regarding Json.

R Mul
  • 1