Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Creating executables with an executable

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Sun Apr 19, 2009 3:47 pm    Post subject: [C++] Creating executables with an executable Reply with quote

How do I create an executable with an executable (e.g. Cheat Engine's trainer and the Cheat Engine)?

I'm planning on having the main executable (the one producing the other ones) to accept an input from the user then create the executable that has a constant variable.

For example, the main executable prompts the user "what is your name?" and you input "Noz3001." The new created executable display "name: Noz3001."


Last edited by nwongfeiying on Mon Apr 20, 2009 5:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

Joined: 09 May 2003
Posts: 25986
Location: The netherlands

PostPosted: Sun Apr 19, 2009 3:58 pm    Post subject: Reply with quote

The way cheat engine does it is have a trainer stub
At the end of the trainer stub ce will append data like which cheats, objects, and their positons

When that trainer stub loads it reads itself and then builds itself up with that information. (Creating objects, allocating memory for addresses and offsets, preparing the execution of aa scripts, etc...)

And that trainer stub in ce is just a simple resource extracted from ce when pressing the generate trainer button

so in your case all you'd have to append to your program is the name and have your program read that last part to find the name to display

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Sun Apr 19, 2009 5:26 pm    Post subject: Reply with quote

Can someone show me a code example? I have the concepts down, but I don't know how to do it.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Apr 19, 2009 6:39 pm    Post subject: Reply with quote

check CE source. DB prolly did some crazy hard over the top way but its there lol
_________________
Back to top
View user's profile Send private message
AlbanainRetard
Master Cheater
Reputation: 0

Joined: 02 Nov 2008
Posts: 494
Location: Canada eh?

PostPosted: Sun Apr 19, 2009 6:55 pm    Post subject: Reply with quote

in net = Codedom
in lotus = MyCompile

_________________
Back to top
View user's profile Send private message Send e-mail
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Sun Apr 19, 2009 8:03 pm    Post subject: Reply with quote

blankrider wrote:
check CE source. DB prolly did some crazy hard over the top way but its there lol


I'll check it, but the CE is in delphi and I need the example in C++?
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon Apr 20, 2009 4:32 am    Post subject: Reply with quote

If you append stuff to an exe, won't it then crash during loading since the windows loader will see the size and checksum in the PE-header are incorrect?
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Mon Apr 20, 2009 5:03 am    Post subject: Reply with quote

There are an execution class in .net but I dont know what it is for. reexecution or what?
_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Mon Apr 20, 2009 8:11 am    Post subject: Reply with quote

wallantia wrote:
There are an execution class in .net but I dont know what it is for. reexecution or what?


Irrelevant to the topic much? And not only that, your post is not even coherent.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Mon Apr 20, 2009 9:52 pm    Post subject: Reply with quote

Here is what you're looking for, I had something similar sitting around from a packer I was making, so it wasn't to hard just to throw the relevant parts together. If you wanted, you could store the subexe as a resource and load it that way.

In main.exe:
Code:
// mainexe.cpp : Defines the entry point for the console application.
//

#include <windows.h>
#include <iostream>
#include <string>

struct global {
   char msg[50];
};

class Subexe {
   BYTE *m_buf;
   size_t m_size;

   bool ReadSource(std::string &src) {
      bool bfRet = false;
      //-------

      HANDLE hFile = ::CreateFile(src.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,  OPEN_EXISTING,  FILE_ATTRIBUTE_NORMAL, 0);
      if(hFile != INVALID_HANDLE_VALUE) {
         m_size = GetFileSize(hFile, 0);
         m_buf = new BYTE[m_size];
         ::ReadFile(hFile, m_buf, m_size, (LPDWORD)&m_size, 0);
         ::CloseHandle(hFile);
         bfRet = true;
      }

      return bfRet;
   }

   LPVOID FindSectionBaseOffset(std::string &section) {
      LPVOID ret = 0;
      //-------

      IMAGE_DOS_HEADER *dosHd = (IMAGE_DOS_HEADER *)m_buf;
      if(dosHd->e_magic == IMAGE_DOS_SIGNATURE) {
         IMAGE_NT_HEADERS *ntHd = (IMAGE_NT_HEADERS *)((DWORD)m_buf + (DWORD)dosHd->e_lfanew);
         if(ntHd->Signature == IMAGE_NT_SIGNATURE) {
            IMAGE_SECTION_HEADER *header = IMAGE_FIRST_SECTION(ntHd);
            for(int i = 0; i < ntHd->FileHeader.NumberOfSections; i++, header++) {
               std::cout << header->Name << std::endl;
               if(section.compare((char *)header->Name) == 0) {
                  ret = (LPVOID)header->PointerToRawData;
                  break;
               }
            }
         }
      }

      return ret;
   }



public:

   bool MakeExe(std::string &dest, std::string &src, std::string &text) {
      bool bfRet = false;
      //-------

      if(ReadSource(src)) {
         global *info = (global*)((DWORD)m_buf + (DWORD)FindSectionBaseOffset(std::string(".win")));
         if(info) {
            ::memcpy(info->msg, text.c_str(), text.length());
            HANDLE hFile = ::CreateFile(dest.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,  CREATE_ALWAYS,  FILE_ATTRIBUTE_NORMAL, 0);
            if(hFile != INVALID_HANDLE_VALUE) {
               bfRet = ::WriteFile(hFile, m_buf, m_size, (LPDWORD)&m_size, 0);
            }
         }
      }

      return bfRet;
   }
};



int main()
{
   Subexe cocks;
   LPSTR src = new char[MAX_PATH], dest = new char[MAX_PATH];
   ::GetCurrentDirectory(MAX_PATH, src);
   ::memcpy(dest, src, MAX_PATH);
   ::strcat(dest, "\\cocks.exe");
   ::strcat(src, "\\subexe.exe");
   cocks.MakeExe(std::string(dest), std::string(src), std::string("Cocks!"));
   delete[] src, dest;
   std::cin.sync();
   std::cin.ignore();
   return 0;
}


In subexe.exe:
Code:
// subexe.cpp : Defines the entry point for the console application.
//

#include <iostream>


#pragma data_seg(".win")
__declspec(allocate(".win")) struct {
   char msg[50];
} globals;
#pragma data_seg()

int main()
{
   std::cout << globals.msg;
   std::cin.sync();
   std::cin.ignore();
   return 0;
}
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Apr 21, 2009 4:04 am    Post subject: Reply with quote

That snippet looks great. Remember that this way will only work if you know that you won't insert more than a certain amount of bytes, 50 in this case. Dark Byte's way however would work with any amount. It depends on what you need it for.

EDIT: Flyte you allocate the m_buf but never delete it.


Last edited by tombana on Tue Apr 21, 2009 8:34 am; edited 1 time in total
Back to top
View user's profile Send private message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Tue Apr 21, 2009 8:16 am    Post subject: Reply with quote

Flyte saved me once again :]
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Tue Apr 21, 2009 12:14 pm    Post subject: Reply with quote

tombana wrote:
EDIT: Flyte you allocate the m_buf but never delete it.


True, but you have to remember that's it's just a paste together of different functions I had sitting in a packer I was making. Most of the code in there could be simplified greatly as well.
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Wed Apr 22, 2009 7:32 pm    Post subject: Reply with quote

lol! I already did this Razz , but I used the VbCodeProvider Class.

C# Example: http://www.codeproject.com/KB/cs/codecompilation.aspx

I don't know anything about C++ but I think this is it...

http://www.c-sharpcorner.com/UploadFile/ChrisBlake/RunTimeCompiler12052005045037AM/RunTimeCompiler.aspx

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Wed Apr 22, 2009 7:44 pm    Post subject: Reply with quote

Cheat Engine wrote:
lol! I already did this Razz , but I used the VbCodeProvider Class.

C# Example: http://www.codeproject.com/KB/cs/codecompilation.aspx

I don't know anything about C++ but I think this is it...

http://www.c-sharpcorner.com/UploadFile/ChrisBlake/RunTimeCompiler12052005045037AM/RunTimeCompiler.aspx


It's not the same thing.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites