Reputation: 553
I have a class library project that in disk is 14,0 KB. is it possible to increase the assembly file size by adding junk bytes?.
For example:
private byte[] junk = new byte[1500];
Will allocate 1500 bytes in memory, but i want them to be reserved in any PE module section (like .data section).
I know C# works with MSIL, but is there any option to reserver physical memory?.
Why i need this?. Well a client ask me to mimic a library he had from a previous developer in functionality and in every detail he could find and that includes file size, name, version, etc. I explain him that anyone with decent knowledge will find that the library is not the original one, but he insist to match it on every detail.
I have an idea why he need this, but thats out of the topic.
Upvotes: 1
Views: 1155
Reputation: 5357
Theoretically, since .Net Dll's and Exe's are standard PE Files that adhere to microsoft PE File Format
http://download.microsoft.com/download/e/b/a/eba1050f-a31d-436b-9281-92cdfeae4b45/pecoff.doc
You should be able to just pad 0 bytes to the end of the file, since the Specification involves the use of chunk sizes and pointer offsets, the end of the file isn't considered on the load and appending 0 bytes to the end of it without modifying any of the sizes or offsets should have no affect on the loading/referencing of the dll.
This is just a theory though. I have not tried/tested this.
If this works, you could just write a simple console app to padd a file by x 0 bytes, something like
Console.Write("Enter File Name To Pad: ");
string fileName = Console.ReadLine();
Console.Write("Enter Number of Bytes to Pad: ");
int bytesToPad = Int.Parse(Console.ReadLine());
using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None))
{
byte[] emptyBytes = new byte[bytesToPad];
fs.Write(emptyBytes, 0, emptyBytes.Length);
}
If that works, you could modify it to get the filename and bytes from the args being passed into the Main function, then set it up as a Post Build Event in Visual Studio that runs after the code is done building.
Upvotes: 2
Reputation: 13960
to enlarge your assembly size can add a image to resources (double click on resosurces.resx) or add references.
I suggest you add some fake pictures, it is the least worst solution:-)
for example
Upvotes: 5