Posted May 11, 20169 yr Can anybody tell me how to convert LinqPad.Resource.dll to .bin? I try to write tool encrypt & decrypt resource for LINQPad: http://www.linqpad.net/download.aspx The tool work fine in decompress .bin file to .dll but it's stuck in compress dll to bin: Error occur -> Reading from the compression stream is not supported Here is binary exe with resource .bin include http://rgho.st/7fLwsbx6Q I hope someone can help me how to fix to improve my to for support compress .dll to .bin The code is easy, I pasted it's here: private void button1_Click(object sender, EventArgs e) //decompress .bin to .dll { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(dialog.FileName, FileMode.Open, FileAccess.ReadWrite); string path = dialog.FileName.Replace("bin", "dll"); File.WriteAllBytes(path, Deflate(fs, false).ToArray()); fs.Close(); MessageBox.Show("Bin Decompressed!"); this.button1.Enabled = false; this.button2.Enabled = true; } } private void button2_Click(object sender, EventArgs e) //compress dll to bin { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(dialog.FileName, FileMode.Open, FileAccess.ReadWrite); string path = dialog.FileName.Replace("dll", "bin"); File.WriteAllBytes(path, Deflate(fs, true).ToArray()); //fail when compress which I can't fix fs.Close(); MessageBox.Show("Bin Compressed!"); this.button1.Enabled = true; this.button2.Enabled = false; } } public static MemoryStream Deflate(Stream src, bool compress) { MemoryStream ms = new MemoryStream(); Deflate(src, ms, compress); ms.Seek(0, SeekOrigin.Begin); return ms; } public static void Deflate(Stream src, Stream dst, bool compress) { DeflateStream ds = new DeflateStream(src, compress ? CompressionMode.Compress : CompressionMode.Decompress); Copy(ds, dst); } public static void Copy(Stream src, Stream dst) { byte[] buffer = new byte[65536]; int read = 0; do { read = src.Read(buffer, 0, buffer.Length); dst.Write(buffer, 0, read); } while (read == buffer.Length); } Edited May 11, 20169 yr by skypeaful
May 11, 20169 yr public static void Deflate(Stream src, Stream dst, bool compress) { DeflateStream ds = new DeflateStream(src, compress ? CompressionMode.Compress : CompressionMode.Decompress); Copy(ds, dst); } Copy-pasting code from github causes lots of problems.. Which stream is source and which is destination when compressing data?
May 12, 20169 yr Author Hi kao, I also rewrite 2 compress code string path = dialog.FileName.Replace("dll", "bin");+ ".dll" File.WriteAllBytes(path, Compress1(dialog.FileName)); // or Compress2 private static byte[] Compress1(String fileName) { using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) using (var compressStream = new MemoryStream()) using (var deflateStream = new DeflateStream(compressStream, CompressionMode.Compress)) { byte[] array = new byte[fs.Length]; input.Read(array, 0, array.Length); deflateStream.Write(array, 0, array.Length); return compressStream.ToArray(); } } private static byte[] Compress2(string fileName) { using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) using (var compressStream = new MemoryStream()) using (var deflateStream = new DeflateStream(compressStream, CompressionMode.Compress)) { fs.CopyTo(deflateStream); return compressStream.ToArray(); } } Compress1 and Compress2 have different result (so strange) and both of 2 encrypted .bin file is crash when decrypt. Can you give some advice to fix?
May 12, 20169 yr Just use Google. http://www.damirscorner.com/blog/posts/20071124-AlwaysCloseDeflateStreamBeforeReadingResults.html
May 12, 20169 yr Tutorial from codebluedev : http://codebluedev.blogspot.com/2016/02/reversing-linqpad-part-1-analysis.html
Create an account or sign in to comment