Recent

Author Topic: Dynamic Application Creation  (Read 1770 times)

Jake012345

  • Sr. Member
  • ****
  • Posts: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
Dynamic Application Creation
« on: June 22, 2020, 10:42:58 am »
Hello!

I want to create .exe files (with really function)  dynamically from an other application.
Just example
For example I run an App. and I pressed a button on form, and on the desktop appears an .exe what delete the main application if I run it.
But I have to write the filepath of main Application in the created.
Check my ProjectShare site and share your content: FPCShare

ASerge

  • Hero Member
  • *****
  • Posts: 1671
Re: Dynamic Application Creation
« Reply #1 on: June 22, 2020, 11:39:35 am »
For example I run an App. and I pressed a button on form, and on the desktop appears an .exe what delete the main application if I run it.
But I have to write the filepath of main Application in the created.
You need to create two projects. In the first project, you will make the necessary removal functionality. And the second one will contain the .exe file from the first project as a resource. At the right time, it will extract it from the resource and save it on disk.

Handoko

  • Hero Member
  • *****
  • Posts: 3762
  • My goal: build my own game engine using Lazarus
Re: Dynamic Application Creation
« Reply #2 on: June 22, 2020, 11:43:44 am »
@jake012345

It sounds you're trying to do something evil.  :D

Anyway, I will achieve the goal like this. First I write the program and generate the exe (that will be put on the desktop later). Then make it as a resource file for combine into the main application.  When the button clicked, I simply export the resource file to desktop.

You can learn more about resource file:
https://wiki.freepascal.org/Lazarus_Resources

Well, I'm late. ASerge already answered.

edit:
You may need to add a new feature in the main program. It should able to scan the hardcoded string in the exported exe and replace it with the path of your main program. It's not hard, I ever done similar thing. You can use stream or the traditional file (block) read/write.
« Last Edit: June 22, 2020, 11:56:00 am by Handoko »

jamie

  • Hero Member
  • *****
  • Posts: 3529
Re: Dynamic Application Creation
« Reply #3 on: June 22, 2020, 01:22:42 pm »
I dont know about os but I believe windows put a stop to reclcling app creation where by it detects suck hacking attempts to lock a app in position like that.

It has been a common hack to render the pc basically useless so you can justify your need all u want , I dont think it's going happen, at least with the current addition of windows.
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 10469
Re: Dynamic Application Creation
« Reply #4 on: June 22, 2020, 01:40:22 pm »
You need to create two projects. In the first project, you will make the necessary removal functionality. And the second one will contain the .exe file from the first project as a resource. At the right time, it will extract it from the resource and save it on disk.
Does not work anymore...( at least not here, but I use devel versions of windows 10)
Addition: you can/could also execute the resource directly, without saving to disk, but not with the latest updates to win10 - 64 bit.
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

Jake012345

  • Sr. Member
  • ****
  • Posts: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Dynamic Application Creation
« Reply #5 on: June 24, 2020, 02:17:37 pm »
no-no-no!  :)

I want to create fast 'suspend-er' .exe-s for my project

When I lock a folder, the locker App. Create a fast unlock exe in the folder, what want the password and send the suspend/un-suspend command to the locker.
Check my ProjectShare site and share your content: FPCShare

Warfley

  • Sr. Member
  • ****
  • Posts: 303
Re: Dynamic Application Creation
« Reply #6 on: June 24, 2020, 03:37:33 pm »
As I already stated in your other thread, I think you are doing it wrong, because you are doing some needlessly over complicated stuff that does not even work, because there is no such thing as an unstoppable process. If you would do it the other way around it would be much easier, portable, and you wouldn't run into such niche problems you are doing now.

That said, what you are trying to do will probably not work as soon as you try running it on a machine that has some antivirus installed, because this is very often used by malware (you have a program that ships the malware, and extracts it).
That you want to dynamically write things into it doesn't make it better, because this is also a common practice for malware, that they modify themselves to a. add information to the executable or b. change their checksums so they don't get detected by antivirus programs.
So it would be a miracle if you get your program running on any properly updated windows computer with an antivirus.

But lets say you are on a computer with no such protection and the OS let's you do this, then this is easy:
1. create your program you want to pack.
2. Add a pattern string as a hardcoded constant to your program, which will be used as the thing you want to change
3. Put this program into the resources of your shipping program (multiple possibilities, e.g. encode it to base64 and put it into a string constant)
4. the shipping program then extracts the program, makes a simple text search-and-replace for the pattern hardcoded in step 2 with the information you want to put in (like your path) and writes it to the filesystem.

And voila, you have a customized executable shipped with your program

Jake012345

  • Sr. Member
  • ****
  • Posts: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Dynamic Application Creation
« Reply #7 on: June 29, 2020, 08:08:52 pm »
How can I use the resources?
I see what's that - otherwise I wanted to do something with that before, but I didn't know, that's what I need - but I can't use it.

I saw the wiki(s) but It's a bit hard to understand (I coudn't use the 'lazres' [?]), and I saw the example in Root folder of lazarus But.... For me..? :D

BTW: Thanks for unstoppable support for everyone!
Check my ProjectShare site and share your content: FPCShare

Handoko

  • Hero Member
  • *****
  • Posts: 3762
  • My goal: build my own game engine using Lazarus
Re: Dynamic Application Creation
« Reply #8 on: June 30, 2020, 06:14:59 am »
Yes, that is the wiki, which has all the information you need.

Do you use Lazarus? If yes, simply forget all the things mentioned by the wiki, forget about LRS Explorer and forget about lazres. Instead, you can go directly to this page:

https://wiki.freepascal.org/IDE_Window:_Project_Options#Resources

Need example code of using the resource? You can download my glSlideshow, in the Form Create event it loads an image from resource stream and uses it as the form's background.

https://forum.lazarus.freepascal.org/index.php/topic,35313.msg256719.html#msg256719

Jake012345

  • Sr. Member
  • ****
  • Posts: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Dynamic Application Creation
« Reply #9 on: June 30, 2020, 03:19:27 pm »
And what's your unit that enable theese to you?
I'm using LResources. And the ide can't find the 'RT_RCDATA'.
So something's wrong in here!
« Last Edit: June 30, 2020, 03:22:11 pm by Jake012345 »
Check my ProjectShare site and share your content: FPCShare

Jake012345

  • Sr. Member
  • ****
  • Posts: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Dynamic Application Creation
« Reply #10 on: June 30, 2020, 04:03:10 pm »
And Can I modify/create the resources dinamycally?

And How is the similar technic the using "bin" files works?
Check my ProjectShare site and share your content: FPCShare

Handoko

  • Hero Member
  • *****
  • Posts: 3762
  • My goal: build my own game engine using Lazarus
Re: Dynamic Application Creation
« Reply #11 on: June 30, 2020, 04:28:01 pm »
And Can I modify/create the resources dinamycally?

Yes, you can. Load the resource to memory, then you can modify it as you like. Pascal is great in modifying data in memory.

Creating resource dynamically? I don't think so.

I'm using LResources. And the ide can't find the 'RT_RCDATA'.
So something's wrong in here!

It's working good here. I'm sure you did it wrong.

And How is the similar technic the using "bin" files works?

Not fully understand what you meant.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2134
  • Compiler Developer
Re: Dynamic Application Creation
« Reply #12 on: June 30, 2020, 04:30:03 pm »
And Can I modify/create the resources dinamycally?

And How is the similar technic the using "bin" files works?

To modify resources in another binary you should take a look at FCL-Res.

Jake012345

  • Sr. Member
  • ****
  • Posts: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Dynamic Application Creation
« Reply #13 on: June 30, 2020, 04:32:13 pm »
I mean a separately resource file with the executable but not IN.
For example MyData.bin=[file1.asd,file2.ttr,file.hgd,...]
Check my ProjectShare site and share your content: FPCShare

Handoko

  • Hero Member
  • *****
  • Posts: 3762
  • My goal: build my own game engine using Lazarus
Re: Dynamic Application Creation
« Reply #14 on: June 30, 2020, 05:02:53 pm »
Did you mean you want to store some data in a separate file?
If yes, then that is easy. You can use a database, manual binary file access, TFilestream, etc.

 

TinyPortal © 2005-2018