Okay, *example* let's say I have an application that allows a user to create different types of message boxes (adding their own text + icon). Now, I want to be able to have the ability to export their "choice messagebox" into a standalone executable. How would I go on about doing this??

Basically, how would I generate (?) standalone exe's from my application? Is there some examples I can look at (preferably masm32 ones :D ) or something I should read into?


thanks..
Posted on 2002-07-15 13:39:56 by tehktik
Use DialogBoxIndirect API there's a sample code in PSDK or MSDN.
Posted on 2002-07-15 13:44:10 by stryker
I would make a main stub and add the custom stuff at the end of the executable... but you can also use strings resources but the generator will only work in win2k (if you use UpdateResource, at least).

I think it was a simple example for a more complex project but for the messagebox case the easiest (and the most reusable for the user depending on the case) solution would be to take arguments from the command line... (title, message, icon)
Posted on 2002-07-15 14:03:28 by JCP
stryker:
I'll look into that right now...

readiosys:
yeah, my actual program isnt the messagebox example and is a bit more complex but i thought that there was like a generic/general way of doing it. also... might i add i'm quite new at programming, heh.


*edit*: a win32asm sample would be very helpful :)
Posted on 2002-07-15 14:17:40 by tehktik
tehktik, maybe I don't understand your question exactly, but...

If the only thing that you want to change in the 2nd executable file is the messagebox stuff, then it really shouldn't be a problem. I'm not sure how you plan on creating the 2nd file, whether you're including it in a resource file or in your .data section or whatever, or if you're just distributing it with your 1st app, but no matter which way you're handling that...

As long as the messagebox is the only thing you want to change you'd just have to take into account the following:

Since the icon your user picks is a constant, just change that number. You'll have to disassemble your app to get the offset though.
Create two buffers in the 2nd exe that're big enough to store the user's text for the message and caption text. Then change those bytes to the user's text.

If you're including the 2nd exe in your exe and then mem mapping it and writing it to disk you can handle those byte changes in memory before writing it to disk. Or if you're including the 2nd app in the same dir as the 1st one, then just open the file with CreateFile and write the changes to it.

Either way, as long as the messagebox is the only thing you're changing it's a fairly easy process.

my $00.02,
will


edit: I forgot about the buttons, which are also constants, so that shouldn't be difficult to change on-the-fly either. Now, if you want your users to be able to change the buttons (ok, ok+cancel,ok+cancel+apply or whatever) AND add functionality on-the-fly to those buttons then that isn't exactly a trivial task. If it's just the appearance of the messagebox that you want them to be able to change then it's pretty simple.
Posted on 2002-07-15 16:50:00 by Will
tehktik,
maybe what you want to do is create a dll or lib? So other people can use your code as well?
Posted on 2002-07-15 17:05:33 by sluggy
Originally posted by Will
tehktik, maybe I don't understand your question exactly, but...

If the only thing that you want to change in the 2nd executable file is the messagebox stuff, then it really shouldn't be a problem. I'm not sure how you plan on creating the 2nd file, whether you're including it in a resource file or in your .data section or whatever, or if you're just distributing it with your 1st app, but no matter which way you're handling that...




You did misunderstand me, my question was basically -- how do i create that second file??? Any sample src??

*edit*
Let me give you another example (just an example):

Main.exe has a an editbox + a "create" button. In the edit box you type in the # of windows you want. You then hit create, and my program makes a NEW, STANDALONE .exe file. You then close Main.exe + run the NEW .exe file and *!!* two dialog windows popup (and you no longer need the Main.exe program).

So, how would I go on about creating this new standalone .exe program??



I just made up that messagebox example because I thought it would be easier to understand what I wanted, I guess it just cause more confusion.

Hope this clears things up..

"
Tehktik
Posted on 2002-07-15 18:25:31 by tehktik
I just thought of an example program which does *basically* what I want to accomplish.

Think of a patch creator.

The PATCHER.EXE program runs, the user selects a few options, and the PATCHER.EXE creates a standalone file.

I want to do that, have my program give the user options, and then create a standalone file. But, I have no idea how to have my program create that new file (since i'm fairly new to asm). And, that is why I'm looking for sample source... now do you understand? :)

Thanks for the replies though !!
Posted on 2002-07-15 18:37:00 by tehktik
So, how would I go on about creating this new standalone .exe program??
Your basically asking a RAD assembler/compiler like program. Are you creating something like a RAD language(E.G. VB). There are 2 ways I can think of.
    [*]Generate the .asm, .rc file based on a template and custom controls made by the end user. Then assemble the .asm and compile the .rc then link both.
    [*]Code it in pure HEX.
Posted on 2002-07-15 20:48:06 by stryker
Well I didn't really misunderstand you then. You'd want to create the 2nd exe before-hand (or at least it's basic shell). Code the generic 2nd program, and store it within your exe (use bin2db in your masm root dir. Then map it into memory (look at Iczelion's file mapping tut), make your changes in memory, write it all to disk. As long as it's basic changes that you want to make, based on your user's choice, it's all within your grasp as a newbie asm programmer.

1) Code an example of the exe that you want your users to be able to 'create.'
2) Store the exe in step 1 inside your .data section as a series of bytes (use bin2db.exe in your masm folder).
3) Take note of the offsets (look at a disassembled listing of step 1) of the constants and other variables which your users will be able to alter.
4) Read the exe from step 1 into memory (read Iczelion's tuts on the subject.
5) Make the necessary changes.
6) Write the whole mess to disk.

As long as it's just basic changes that you'd like your users to be able to make, this method is your best bet. If you want to make some type of fully funcitional compiler with asm, like visual basic or something then good f'ing luck. But if it's just basic changes like a patcher or that messagebox example then this is what you want to do.

g'luck,
will

edit: Take your patcher example. The user would select an icon, some text, and select which bytes they want to change at which offsets (either manually entering the data or by your program comparing two different programs and gathering the byte/offset pairs that way). So you've got a patch.exe template stored within your program. You write your patch template into memory. Write your users textual data into the predefined .data or .data locations (make sure you allocated enough space). Just to clarify, do something like szUserText db 64 dup(0) which will leave a 64 (decimal) byte space in your .data section of your exe that you can fill with the user's text. I hope you get the picture. Then pre-allocate two big enough arrays to hold your bytes_to_change array and your offsets_at_which_to_change array. Write your user's info to those arrays using the same method. The icon will be tricky if it's bigger then the original icon that your patch.exe template used. If you're using an nt based os then you can just use the UpdateResource api like someone else mentioned. If you're using Win9x then you'll have to manually **** with the .rsrc section of the patch.exe template which will be a ***** for you I think. Other then that it's not that tough of a project.

If you're really serious, then start with your messagebox example. The MessageBox api is simple:
push 0
push 0
push 0
push 0
call MessageBox

That creates a messagebox with no owner, the default "error" caption, no text, and the 'ok' button. Follow the instructions above to make your user's changes. Maybe tomorrow at work I'll code a simple example based on the messagebox example but I honestly think you're capable of doing something like this.
Posted on 2002-07-15 21:39:07 by Will
Will (and the rest of you), thanks for the help.

I will first try to create another program (the messagebox example) because it seems easier than what I am wanting to accomplish. I've got a pretty good idea on how to accomplish it now, but an example (if you have the time) would always be helpful. Thanks again!!!
Posted on 2002-07-16 00:05:21 by tehktik
Imho, an exemple wouldn't help much since it doesn't depends much on the langage...

You generator puts some info at the end of your file stub (a program you coded to interpret what is at the end)...

The key is to have two programs... a stub (the target program) one and the generator that creates the new file...

I hope that your reasons to code such a patcher are legitimate, as we are not supporting illegal activities here, but I know it may exist some as I already coded such utilities for fully legitimate and legal reasons...

Regards,

PS : Starting by the messagebox is a good way to go to understand, implement, and enhance such a system...
Personnaly, I like to test if an idea works with a minimalist program before to go in the main one...
Posted on 2002-07-16 01:06:45 by JCP


Personnaly, I like to test if an idea works with a minimalist program before to go in the main one...



Same way I do it :)
Posted on 2002-07-16 01:41:24 by bazik
two ways come into my mind... the easy one: please check
out hutchs prostart utility in the masm package, this tool can
generate full compilant asm sources, you just have to choose
how many buttons/etc. you want to have. YOUR prog could
do the same and after creating the source you could compile
it automaticly with masms standard compiler. you can also
grab the compiler output via pipe so the user wouldn't notice
that you're compiling something in the background. 2nd way
would be handcrafting a full working pe executable...
generating a simple one isn't such hard if you're familar with
the pe architecture but if you want it to by more flexible it
could be very hard to do this... i think it's to much work for
nothing... oh and check out this
(you have to download it via right-mouse button because
of tripod)
Posted on 2002-07-16 04:21:29 by mob
Heh, I gues I am having a hard time being understood (by some). I'm not coding a patcher -- as I used a patcher as an example because a patcher was the best example for what I wanted to accomplish (..a program that can make standalone .exe's). I'm not creating a compiler, as some of you think I am.

And, I am going to start with the messagebox program (which was also first just an example, heh).

Thanks again.
Posted on 2002-07-16 12:59:10 by tehktik
code it in HEX and save it as .exe(binary) http://www.asmcommunity.net/board/index.php?topic=4638&highlight=win32hex

I've already pointed out the obvious one: combine the files from the different templates(pushbutton.asm, editbox.asm ...) depending on the user choices... into one .asm file and assemble it.
Posted on 2002-07-16 13:21:46 by stryker
Alright, here's a little example of what I was trying to get at Tehktik. Please don't take this as an example of good coding though. I think everything is self explanatory, so there aren't any comments. If there's anything that needs clarification please let me know.


will

p.s. I stole the shell from one of Icz's tuts.

edit: There's no error checking to make sure that everything's filled in by the user because the 3 buffers are filled with 0's, so everything defaults to 0:
MB_OK equals 0
no msg text equals 0
no caption text equals 0
....so if you start the program in the zip and hit the 'create' button with filling in anything you'll just get an exe file with a blank messagebox with the 'ok' button only.
Posted on 2002-07-16 20:56:18 by Will
Yes :D

Will, this is exactly what i was looking for. Thanks!

*edit*

Exactly how do I get the #'s in the _ExeTemplate_?? Did you just make a "generic" messagebox .exe then get the hex values from there??
Posted on 2002-07-16 23:38:38 by tehktik
I made a generic messagebox program (which I should have included):


.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.data
MsgCaption db 64 dup(0)
MsgBoxText db 64 dup(0)
MB_INFO dd 0

.code
start:
invoke MessageBox, NULL,addr MsgBoxText,addr MsgCaption,MB_INFO
invoke ExitProcess,NULL
end start

Then I opened it up with 'bintodb.exe' in the masm32 folder and copied the output from that program into the .data section of the MessageBoxCreator program. I was going to write the ExeTemplate into memory, make the changes, and then dump it to disk but it really isn't necessary. So I chose instead to make the changes to the ExeTemplate data and then write the whole thing to disk. Also, I didn't do any checking to ensure that the user stayed within the 64 byte limit on the two text buffers. This was just more of a proof of concept program, so excuse the sloppy coding.

will
Posted on 2002-07-17 08:41:39 by Will
tehktik,

If I have got you right, you want an app that will produce different EXE files within a specified range of variation that the user can select.

Idea is to make an EXE file that has a few variables that control what the output will be. With something simple like a message box, the number of buttons, the text for the message and the title and the styles used.

Have a range of variables that can manipulate these different things, then write the values for the variables directly into the EXE file, the MZ header, part of the PE header if the file is compressed and has a blank space there or at the end of the file if there will be a lot of data there.

Then you store the EXE file in another and when the user wants to create a file, you write it with the set of variables to disk as a seperate EXE file.

I have done it before with a few of my programs so that the ewnd user could dial up a few differences.

Regards,

hutch@movsd.com
Posted on 2002-07-17 09:48:59 by hutch--