Newtonsoft JSON deserialization not working while using ConfuserEx

1.5k Views Asked by At

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!

2

There are 2 best solutions below

4
Peter B On

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; }
}
0
R Mul On

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.