-1

I am writing an installer. This installer should be able to embed 1..n files in .exe body. I dont want to ship 2 seperate files (like an .exe and a .cab).

First i have tried mono.cecil variant to Add new external resources (each file is single resource), but i already hit its limits because it is internally using byte[] to read the file and analyse it, then it modifies the buffer and writes. I get Memory overflow by files > 500MB. I have also tried to debug Mono.Cecil, but no success. The byte[] and MemoryStream is used inside and its huge complicated library to attempt to change.

Second: I had the idea to add the files simply to tail of the .exe and read them from there. I am using a class for this:

        // signature is being used to identify the metainformation
        var Tail = new msTailFiles(msTailFiles.RandomSignature(), FN);

        // Add to tail
        foreach (var F in Directory.EnumerateFiles(@"c:\Windows"))
            Tail.AddFile(Path.GetFileName(F), F);

        // Read file info
        var AllFiles = Tail.GetFileNames();

        // Take files from tail and put to filesystem
        foreach (var F in Tail.GetFileNames())
        {
            Tail.GetFile(F, File.Open(@"f:\copy\" + F, FileMode.Create));
        }

With this method i am able to extend existing .exe file up to filesystem filesize limit which is good.

But I have trouble if i go over ~ 1.5GB sizelimit, I can read .exe file information in explorer successfully, so i dont break the .exe structure, but if i start this file i get error: "This applicaton could not be started." from explorer. Also it takes around 30 seconds to get the error message, it looks like windows is trying to load whole 2GB into memory or analyse somehow (maybe IL does?). All Metainformation such as Copyright, Size, Type, Owner, Icon of .exe is still displayed, so all looks good, but something has trouble with my style.

So my question is: what might be my problem? Does anyone have any other suggestion instead of using TailFiles() method or Mono.Cecil method?

turkey
  • 1

1 Answers1

0

Here is how i have solved this issue:

I have put Target CPU to "Any CPU" and this problem has disappeared completely. With this TailFiles way i can now add unlimited number of custom data to tail of the file. For now Anti-Virus Software Kaspersky does not say anything bad to that not-too-elegant very-efficient way of storing other files in tail.

turkey
  • 1