【问题标题】:Obfuscar - skip obfuscation of anonymous typesObfuscar - 跳过匿名类型的混淆
【发布时间】:2023-02-19 17:45:47
【问题描述】:
我使用的是开源混淆软件“Obfuscar”。有没有办法将其配置为不混淆我的匿名类型中的属性名称?
我正在使用 RestSharp 发送 HTTP 请求,我的 Json 正文内容是匿名类型。
request.AddJsonBody(new {
data = new {
type = "attachments",
attributes = new {
name = "foo"
}
}
});
我希望它不要重命名匿名类型中的那些属性,如“数据”、“类型”等,因为重命名它们会影响它序列化到的 Json 字符串。
【问题讨论】:
标签:
c#
obfuscation
anonymous-types
obfuscar
【解决方案1】:
在 github obfuscar 问题中,我找到了this answer,它对我有用
您需要在 Obfuscar xml 配置文件中创建节点:
<SkipType name="*AnonymousType*" skipProperties="true" skipMethods="true" skipFields="true" skipEvents="true" skipStringHiding="true" />
完整的 xml 配置文件示例:
<?xml version="1.0" encoding="utf-8"?>
<Obfuscator>
<Var name="OutPath" value="C:TMP" />
<AssemblySearchPath path="C:UsersuserDocumentsProjectsMyProjectinRelease
et6.0" />
<AssemblySearchPath path="C:Program FilesdotnetsharedMicrosoft.NETCore.App.0.0" />
<Module file="C:UsersuserDocumentsProjectsMyProjectinRelease
et6.0\MyProject.dll">
<SkipType name="*AnonymousType*" skipProperties="true" skipMethods="true" skipFields="true" skipEvents="true" />
</Module>
<Var name="KeepPublicApi" value="false" />
<Var name="HidePrivateApi" value="true" />
</Obfuscator>
接下来需要启动obfuscar.exe -s "path_to_xml_configuration_file"
另请参阅 Obfuscar 文档中的部分
https://docs.obfuscar.com/getting-started/configuration#exclusion-rules-by-configuration