Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newtonsoft JSON deserialization not working while using ConfuserEx

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!

like image 978
gave Avatar asked Jun 03 '26 20:06

gave


1 Answers

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; }
}
like image 51
Peter B Avatar answered Jun 05 '26 09:06

Peter B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!