Can I import a .txt file and export it as an .exe file?

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 5510 Views - Last Post: 09 December 2011 - 09:50 AM Rate Topic: -----

#1 Arastall  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-November 11

Can I import a .txt file and export it as an .exe file?

Posted 27 November 2011 - 04:00 PM

I am trying to write a program that can open text files and export the text (which would be written in VBScript) as an .exe. Can't think of anything more to add.
Is it even possible?

Long story:
The program is a host. Clients connect to it.
When the client sends "/create [name of exe]" with a winsock control, the host will wait for the content of the .txt it will write.
The content of the next message over winsock will me saved in a .txt.
The host will then open this text file, then save it again as an .exe.
The client will then be able to send "/run [name of exe]", and the host will run it.
Is it possible?

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Can I import a .txt file and export it as an .exe file?

#2 DimitriV  Icon User is online

  • >not activating your almonds
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,672
  • Joined: 24-July 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 27 November 2011 - 05:01 PM

To cut a long story short, you need a way to parse the code, build and compile it. So unless you have a way to do it, it's going to be very hard.
Was This Post Helpful? 0
  • +
  • -

#3 Arastall  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-November 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 27 November 2011 - 05:38 PM

View PostjimmyBo, on 27 November 2011 - 05:01 PM, said:

To cut a long story short, you need a way to parse the code, build and compile it. So unless you have a way to do it, it's going to be very hard.


Can a program self-modify itself so dramatically that it changes completely? Self-modification isn't impossible. It doesn't have to build a whole new .exe, it can just self-replicate and self-modify.
Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 856
  • View blog
  • Posts: 2,246
  • Joined: 28-March 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 27 November 2011 - 05:46 PM

An exe file is NOT a text file. It contains headers, sections, opcodes, strings etc... Sure you can "hand build" an exe, but why? If you get something wrong, it won't run. Self modification is surely possible, but most AV will detect it. What are you trying to do exactly?
Was This Post Helpful? 0
  • +
  • -

#5 ricardosms  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 73
  • View blog
  • Posts: 301
  • Joined: 02-April 10

Re: Can I import a .txt file and export it as an .exe file?

Posted 27 November 2011 - 05:54 PM

It was possible in DOS Mode, you could convert a text file to a com executable file and using bintoexe utilities convert it to an exe file. you would run the program and get the text displayed on screen. These were 16 bit programs. They won't work anymore on vista or windows 7.

Anyway, check this link, there is a vb6 code that may give you some ideas.

http://www.planetsou...d=2071&lngWId=1

couldn't you just execute the vbscript?

This post has been edited by ricardosms: 27 November 2011 - 06:03 PM

Was This Post Helpful? 1
  • +
  • -

#6 ricardosms  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 73
  • View blog
  • Posts: 301
  • Joined: 02-April 10

Re: Can I import a .txt file and export it as an .exe file?

Posted 28 November 2011 - 05:27 AM

Hi.
Tis is the listing of a TurboC program that I wrote in 1997. It would read a text, add a heading and a footer and produce a com executable that would display the text on screen. It was compiled in small model. It can be converted after to exe with a DOS utility.
The output could be redirected or piped.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char txt[]="\xB4\x09\xBA\x09\x01\xCD\x21\xCD\x20";
char a[]=".COM",b[80],y,*p;
char c[80];
char fname[9],dir[64],drive[3],ext[5];

void main(int argc, char *argv[])
{
FILE *fopen(),*fp1,*fp2;
if(argc<2)
  {
    printf("\I need an input file..."); 
    exit(1);
  }
strcpy(c,argv[1]);
if((fp1=fopen(c,"r"))==NULL)
  {
    printf("\Couldn't open input file..."); 
    exit(2);
  }

_splitpath(argv[1],drive,dir,fname,ext);
strcpy(ext,".COM");
strcpy(c,fname);  
strcat(c,ext);

if((fp2=fopen(c,"w"))==NULL)
  {
    printf("\nCouldn't open output file..."); 
    exit(3);
  }
fputs(txt,fp2);
while ((y=getc(fp1))!=-1)
  {
    if(y!='$')fputc(y,fp2);
    else fputc(' ',fp2);
  }
fputc('$',fp2);
fcloseall();
}



I hope it will give you some ideas.
Was This Post Helpful? 1
  • +
  • -

#7 Arastall  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-November 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 28 November 2011 - 08:54 AM

View PostGunnerInc, on 27 November 2011 - 05:46 PM, said:

An exe file is NOT a text file. It contains headers, sections, opcodes, strings etc... Sure you can "hand build" an exe, but why? If you get something wrong, it won't run. Self modification is surely possible, but most AV will detect it. What are you trying to do exactly?


AV is not a problem as it's not a virus. I'm just trying out different ways of easily adding functions to a program.

Thank you, ricardosms for the very helpful link.

Then again, I'm sure there are way easier ways than sending .txt files. One option is to build an exe in VB, rename the exe to txt, then send the content of the txt to make an exact replica, then rename the txt on the other computer back to exe. It works sometimes. Other times I get an error message regarding 32/64 bit Windows. But I'm figuring it out.
Was This Post Helpful? 0
  • +
  • -

#8 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 856
  • View blog
  • Posts: 2,246
  • Joined: 28-March 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 28 November 2011 - 03:40 PM

Well if you are trying to send a binary file as text, that that is problem number one, you will loose info here and there.

You can't just add functions to an exe all willy nilly. If you want to easily add functions to your program, then allow your program to use addins.
Was This Post Helpful? 1
  • +
  • -

#9 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 28 November 2011 - 04:33 PM

Sounds like a compiler. Why don't you just create an application that can load text files to which you or your client use your very own language to which the program, reads and parses for commands. At this point your program can dynamically change(I suggest using dll's for the parsing of your own language) adding functions, or taking them away, as well as designs and other things. Compilers are quite complex, and while it's been done obviously it's not some simple task that anyone can shoot a few links at you and make possible.
Was This Post Helpful? 1
  • +
  • -

#10 Arastall  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-November 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 29 November 2011 - 04:11 PM

Too complex, trevster344, I just started with VB a month ago (and I have no previous experience with any programming language), but thanks anyway.

I noticed the loss when transferring text, saving the .txt as .exe, hoping it would be identical.

And no, I don't really need the original exe itself to modify. The only thing it needs to be able to do is start other exes. They will appear to be a part of the original one. I might be overcomplicating things. I'm sure I can send exes or dlls over a winsock control somehow, right? All files are 1s and 0s in the end, right?
Was This Post Helpful? 0
  • +
  • -

#11 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 856
  • View blog
  • Posts: 2,246
  • Joined: 28-March 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 29 November 2011 - 04:26 PM

Technically, yes they are just binary numbers. A string terminator is 0 - null (not the number) a binary file - exe, dll, and others contain plenty of nulls, so if you send as text (send and receive) using string functions, then you will only get up to the first null encountered.
Was This Post Helpful? 0
  • +
  • -

#12 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 29 November 2011 - 06:18 PM

Not simple, not impossible, just difficult for a beginner. ;) I think you'll want to get some more experience in programming other simpler applications, or bits and pieces of this one till you're ready to complete it, or start on it once more. Especially if you are learning like the rest of us with the cheese block method(learning this and that, leaving many holes around what you learn).
Was This Post Helpful? 0
  • +
  • -

#13 ricardosms  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 73
  • View blog
  • Posts: 301
  • Joined: 02-April 10

Re: Can I import a .txt file and export it as an .exe file?

Posted 01 December 2011 - 10:15 AM

View PostArastall, on 29 November 2011 - 06:11 PM, said:

And no, I don't really need the original exe itself to modify. The only thing it needs to be able to do is start other exes. They will appear to be a part of the original one. I might be overcomplicating things. I'm sure I can send exes or dlls over a winsock control somehow, right? All files are 1s and 0s in the end, right?


You could make some kind of menu program and start other programs like this:

System.Diagnostics.Process.Start("C:\Myprogram.exe")



About sending binary files through the internet, you could send a zip file with no problem and expand it on the other end.
Was This Post Helpful? 0
  • +
  • -

#14 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: Can I import a .txt file and export it as an .exe file?

Posted 01 December 2011 - 10:24 AM

Well generally when game companies update their software they write new binary to the file rather than have you redownload the whole file over and over. So it is possible to write new binary. How? I don't know. I'm not so certain vb.net is your ideal language for such a process. But I could be wrong. I know it's possible though.
Was This Post Helpful? 0
  • +
  • -

#15 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8375
  • View blog
  • Posts: 31,132
  • Joined: 12-June 08

Re: Can I import a .txt file and export it as an .exe file?

Posted 01 December 2011 - 10:35 AM

Yes the only way to do this would be for you to code a whole 'addin' system, but frankly this all sounds hinky.

Here's a link I found a while back on the topic..
http://www.dreaminco...dd-ons-nettuts/
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2