| View previous topic :: View next topic |
| Author |
Message |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Apr 19, 2009 3:47 pm Post subject: [C++] Creating executables with an executable |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25986 Location: The netherlands
|
Posted: Sun Apr 19, 2009 3:58 pm Post subject: |
|
|
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 |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Apr 19, 2009 5:26 pm Post subject: |
|
|
| Can someone show me a code example? I have the concepts down, but I don't know how to do it.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Apr 19, 2009 6:39 pm Post subject: |
|
|
check CE source. DB prolly did some crazy hard over the top way but its there lol
_________________
|
|
| Back to top |
|
 |
AlbanainRetard Master Cheater
Reputation: 0
Joined: 02 Nov 2008 Posts: 494 Location: Canada eh?
|
Posted: Sun Apr 19, 2009 6:55 pm Post subject: |
|
|
in net = Codedom
in lotus = MyCompile
_________________
|
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Apr 19, 2009 8:03 pm Post subject: |
|
|
| 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 |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Mon Apr 20, 2009 4:32 am Post subject: |
|
|
| 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 |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Mon Apr 20, 2009 5:03 am Post subject: |
|
|
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 |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Mon Apr 20, 2009 8:11 am Post subject: |
|
|
| 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 |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon Apr 20, 2009 9:52 pm Post subject: |
|
|
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 §ion) {
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 |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Tue Apr 21, 2009 4:04 am Post subject: |
|
|
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 |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Apr 21, 2009 8:16 am Post subject: |
|
|
| Flyte saved me once again :]
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Tue Apr 21, 2009 12:14 pm Post subject: |
|
|
| 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 |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Wed Apr 22, 2009 7:44 pm Post subject: |
|
|
It's not the same thing.
|
|
| Back to top |
|
 |
|