Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:02:27+00:00 2026-05-31T20:02:27+00:00

I’m trying to make a program packer but i always fail because when i

  • 0

I’m trying to make a program packer but i always fail because when i concat three strings(one contains prefix of source, one contains executable content, other contains suffix of source) content overflows into suffix. Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.IO;
using System.IO.Compression;

namespace ProgramPacker
{
    public partial class Form1 : Form
    {
        static string prefix = @"using System;
using System.Collections.Generic;
using System.Text; 
using System.IO; 

namespace ProgramPacker 
{ 
    class Program 
    { 
        static string inside = @" + "\"";
        static string suffix = "\";\n" + @"static void Main(string[] args) 
        { 
            string temp = Path.GetRandomFileName() +" + "\"" + @".exe" + "\"" + @";
            BinaryWriter sw = new BinaryWriter(new FileStream(temp, FileMode.Create));
            sw.Write(inside);
            sw.Flush();
            sw.Close();
            System.Diagnostics.Process.Start(temp); 
        } 
    } 
}";
    public string code = "";
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        openFileDialog1.ShowDialog();
        BinaryReader br = new BinaryReader(new FileStream(openFileDialog1.FileName, FileMode.Open));
        byte[] data = new byte[br.BaseStream.Length];
        br.Read(data, 0, (int)br.BaseStream.Length);
        br.Close();
        string inside = Encoding.UTF7.GetString(data);
        code = string.Concat(prefix, string.Concat(inside, suffix));
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Console.Write(code);
        CSharpCodeProvider cs = new CSharpCodeProvider();
        ICodeCompiler compile = cs.CreateCompiler();
        CompilerParameters param = new CompilerParameters();
        param.GenerateInMemory = false;
        param.ReferencedAssemblies.Add("mscorlib.dll");
        param.ReferencedAssemblies.Add("System.dll");
        param.ReferencedAssemblies.Add("System.Core.dll");
        param.GenerateExecutable = true;
        param.OutputAssembly = Environment.CurrentDirectory + "/a.exe";
        param.WarningLevel = 4;
        CompilerResults comp = compile.CompileAssemblyFromSource(param, code);
        foreach (CompilerError error in comp.Errors)
        {
            MessageBox.Show(error.Line + " " + error.Column + " "  + error.ErrorText);
        }
        MessageBox.Show(comp.PathToAssembly);
        MessageBox.Show("Finish!");
    }
}

}

It outputs:

using System;
using System.Collections.Generic;
using System.Text; 
using System.IO; 

namespace ProgramPacker
{ 
    class Program 
    { 
        static string inside = @"?ãÎoüoy±ôãøÿ?ÿQÔh¦Rt!?^ÿyóë=G:Fÿ»??¿Ç/}òKÿ?úõßû3õMù?c·?Äûòëoª?À_Û>LÖïá^öÿ·õ©üüòcÊ?ª??÷Ô?î:^ȯÏäG¶?ù ?ñË?oñëy:ôã7??ò@ÚyN?w¿=?ëÆ÷ëÛßTëºÓ»yßüø]áå{ö/àïªêL©Oÿ;ú5rù% ä¸?1)Ï?¥?y®ÿ]0QL8û×ÖGòów±?øÿèü[?ª~éá¿ÿó£üüJ~ܹ
Êw¡h??/?úçeñÈ_?¿?ü½L^ywü7?,ùÅû¿ß£ó÷w?É~Ç????ê?ÿQÌyç¿??¹Cö×vZ__>?? ûïx?_ü"õ!ì; ;ùõåÇ?ú3*­¿   @ÿV?èÿ¿Ë??/½P¶y?â¡??ùñÿÑæä/A¶_ò?v??ÿ?ÿQtÄx÷w?O'N?u$ÿk÷U«yÆò?£.Y?ùw(?ßÔ6ÿ]2ÿeUÆò¿?ضö·ßO~ü#*y£Jæ·Ä w yóYëï´
õ}y¡ä¨ù÷YPdú?Z©Óé¼R?æg?ÀSyà쬽Éÿ­ûÁ?ym>ut?ÿA??>?¿[ôçF ê´)9ß9xÿ£¿?
åùïyí ÁTlù
-ùñ?Òÿ·!·
E?£üO5÷]çºy?7Áè¿?Zô?(å§
#ü¥úõ®?o«âû]0Èßä7¿à??¿õ?d?ѵ;Jü_K?úAMìT>Àü1mR0sâ¿ê¨õ{äö×ó??¿.úÿõ½Eä?ÔïÿÎÿ±³v'ÿûìw ?»oÃø1±WtB
É¡wì&øuå£Îÿ?Éw?|úWÿ=ö÷_ÿ·?y®YWöwû¿ßß?Öe'û?%?yß/×Àî-yÿ.?8åóù?ûÇÚ6ÿÂßøï?Áàï?{8Zy?¿Å5yø    ÇpÏ9=ó»üÑ>Õ?Èÿ?Y¿,?ëÿ?Êçÿì_}E?÷Ûú|î$ò÷ø}Jÿ^Êtò¿?@á|ò{Ø`<ªÿQ?QLæ½õo)¿ü&¿áÂÿ¼ó¿_÷7yMå8)¿Ùo'¿õ±üü=~#LÚ¿ó§¢Ë÷üO?Æ?å÷WJÍ$¾¸øW?A?Òÿ(09Áÿà³_ëÿù3l?SWYµßô÷¤~?ÀG¿ñ
??Às%ÍyÑ;Ò¸!ÿ?_Iÿ¼¼í/Ôrö
?T´ôÑùyǹßE~üV?ñ¿C~VßùuÿG   X8|._¼Å_:Æü-?îü:?øì?|W  ¤ÃÓW01?$å×?Û#ùIÿû·1:4û½ü._y^òÙNó?º1?ßIÍ?ÿ¿ß_~|ÖùX?@?në_B?¡µ~_×ãÿhãèïØÏßì¡yïôk_y;HÿÛyÿàâ/sÀ??? $ìw0Jüßü«@?ûo?¿îËX
´úÏ?Æ?Y>øçÿFpyÅÿèËöyK¡²Ì`}ù½Ò¿íÿÀñn"?Í?ëOëi»ò¹Î~çÿ?_òüîÿh£ôáêDøÏÿ¶?ç·fy ÄúçÿÖÿ?yÿ?¿?ã0ÿ¿Ë÷åå?ÿQ|ü/ü9¿?÷×Hè×ÉÏ#õ??æ?ÿâ?x?ß?5µ}~Øy¾ß^øè{¿
y{íü;Òÿ¿óú7¤¡î?»    yû?ÀÓøiP?ÿÀ_ôK?Gëªíá@??ú%íwS×ñ¿¨#Û¦ÿÿÛªy\]¼÷Z~yR~ü¶ÿ£hû???ÇãÿQVèÿ©?÷{O?Gë¬ ??¡ø\«L` æcëí¿ ½?»?ü?oë¼Ätÿ>ò÷£­_¯ÖiÄ?¯ÿÓ¿÷Ï?(c¦äàéûèó?ü£´çÕè4üy_
r?qÆ¿ø'?KÿÀ_ó×xùkÔ¿FõkÌ~õ¯1y5Ú_ã'??n~âר~å¯ñkü»¿Æø×رÿÿ5~?_ã7ø5~Í_ã?Z4ÔrñkL~ò׸?5Òßûÿ??ñïñnQ¦?yYÕò³vÇ;¥ùrZÍ?åÅg}õæÙöÁGiÓfËYVVËü³®óæ£ßãè7NgM?/&åuJrustInfo>
</assembly>
; 
        } 
    } 
}

Any help?

EDIT: Why is everyone down-voting? I just asked a question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:02:29+00:00Added an answer on May 31, 2026 at 8:02 pm

    You’ve run into a problem of representation, one that you’re not likely to fix with your code as-is.

    However, you can choose to follow a similar approach with just minor modifications (which don’t actually compress your program much at all).

    1. Remove the @ from the definition of the string inside. This is one of the causes of your problems.
    2. You can’t just put a BELL character or NUL character in-line in your string, instead write out their unicode escape sequences:

      string inside = String.Concat(
          data.Select(b => String.Format(@"\u{0:X4}", b)));
      
    3. Now, in your suffix code, reinterpret your inside string as characters which you cast to bytes:

      sw.Write(inside.Select(c => (byte)c).ToArray()); // hardly efficient
      

    I was able to use these modifications and successfully “pack” and execute the following:

    C:\temp>type hello.cs 
    using System;
    class M {
    static void Main(string[] args) {
    System.IO.File.Create("hello.world");
    }
    }
    
    C:\temp>csc hello.cs 
    Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    
    C:\temp>pack.exe hello.exe 
    3584 bytes
    
    C:\temp>a.exe
    
    C:\temp>dir *.world 
     Volume in drive C is OSDisk
     Volume Serial Number is AABD-D663
    
     Directory of C:\temp
    
     03/22/2012  16:36                 0 hello.world
                   1 File(s)              0 bytes
                   0 Dir(s)  279,351,762,944 bytes free
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.