I'm analyzing a .NET DLL with dnSpy to understand how the DataZipCompression.LoadString method decompresses and decrypts data into an XML string. My goal is to reconstruct the algorithm so that I can implement the decryption and decompression process externally.
Here’s a key code snippet from the DLL:
<Module>.DataZipCompression.LoadString(
<Module>.?A0xdbfabc02.g_pDataZipCompression,
ref basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>,
ref basic_string<char, std::char_traits<char>, std::allocator<char>>,
true
);
Full fragment:
basic_string<char,std::char_traits<char>,std::allocator<char>
> basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>;
<Module>.std.basic_string<char,std::char_traits<char>,std::allocator<char>
>.{ctor}(ref basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>);
try
{
<Module>.DataZipCompression.LoadString(<Module>.?A0xdbfabc02.g_pDataZipCompression, ref basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>_u0020>4, ref basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>, true);
byte[] array3 = new byte[<Module>.std.basic_string<char,std::char_traits<char>,std::allocator<char>
> .length(ref basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>)];
for (int i = 0; i < array3.Length; i++)
{
sbyte* ptr3 = <Module>.std.basic_string<char,std::char_traits<char>,std::allocator<char>
> .[](ref basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>, (uint)i);
array3[i] = (byte)(*ptr3);
}
UTF8Encoding utf8Encoding = new UTF8Encoding();
string @string = utf8Encoding.GetString(array3);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(@string);
dataContainerProperties = genericSerializer.FromXmlStringIgnoreParentName(xmlDocument.OuterXml);
}
catch
{
<Module>.___CxxCallUnwindDtor(ldftn(std.basic_string<char,std::char_traits<char>,std::allocator<char>
> .{dtor}), (void*)(&basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>));
throw;
}
<Module>.std.basic_string<char,std::char_traits<char>,std::allocator<char>
> .{dtor}(ref basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>);
What I’ve Tried:
- Decompiling the DLL with dnSpy to locate the DataZipCompression class and the LoadString method.
- Analyzing the method parameters and the flow of data after decompressing.
- Tracing data manipulation and understanding how the XML string is produced.
I’m looking for insights or guidance on reconstructing this algorithm for use outside the DLL. Any help or suggestions on dynamic analysis, data pattern recognition, or alternative debugging approaches with Visual Studio, WinDbg, or other tools would be greatly appreciated.