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++ AutoAssembler (Or rather Use CE's AutoAssembler in C++)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source
View previous topic :: View next topic  
Author Message
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Sun Oct 07, 2012 6:10 am    Post subject: C++ AutoAssembler (Or rather Use CE's AutoAssembler in C++) Reply with quote

Hey Hitler! Ok well I haven't made a trainer in a long time, and that's because I got sick of having to re-write all the scripts I make with CE's AutoAssembler into C++ form (it's easy but time consuming and usually makes a mess of my source files Laughing)

So I had an idea (well not my idea I know others have already done it in the past already) If I could get remake CE's AutoAssembler into C++ (just the assembler and autoassembler parts of it) then I could easily just load any script into my trainer and have it execute either the enable or disable part of it I would manage the scripts inside the trainer, and it would just be an easy call to execute either part like this:

Code:

int AutoAssemble(char*, bool); //function definition


AutoAssemble(myScript, 1); //enable
AutoAssemble(someScript, 0); //disable


It would take a standard c-style char array string as the script, and a boolean whether to execute the enable or disable part...

However I'm not ready to do all that just yet as it's a huge undertaking converting it all to c++ code from pascal (formerly delphi but it looks the same to me as delphi code lol) especially since I'm not comfortable with pascal syntax just yet, but I'm gonna play around with it enough that I get comfortable Smile


So in the meantime though, I thought I would at least leave the code in its current form and compile a standalone DLL of just the autoassembler + assembler units...

I got CE's latest source and the second latest version of lazarous + fpc (CE wouldn't compile with the absolute latest lazarous)

Then I got it to compile, and was looking around the code trying to understand of it, and it seems like a pretty nice syntax, though I'm more comfortable with C/C++ style syntax at the moment... I think I got the main idea though... The assembler just takes a line of assembler code and turns it into machine code bytes, where as the auto assembler actually reads through our AA scripts and does all the converting of labels into actual addresses and all that good stuff.

I noticed a line in Assemblerunit:
Code:

 uses {$ifndef autoassemblerdll}CEFuncProc,{$endif}symbolhandler, lua, luahandler, lualib;


But this seemed to good to be true, to just define autoassemblerdll and it would compile a dll with just AA instead of a full CE exe!!? Is it? lol

I tried it however putting a {$DEFINE autoassemblerdll} at the top and hitting compile... I got several errors but not really that many... mostly processlisthandler.is64bit related which I fixed by commenting out those code lines (I don't require 64bit AA although it would be nice) and a couple places where 'function ConvertHexStrToRealStr(const s: string): string;' function was used... and one place where 'function StrToQWordEx(s: string): qword;' was used I copied those functions from CEFuncProc (hint gotten from that $ifndef line Wink) into Assemblerunit and then I got it to compile!

I couldn't find an autoassembler.dll / ceautoassembler.dll in the project folder though, so I'm guessing yes it was just wishful thinking that after getting it to compile without CEFuncProc being included and defining that define it would just produce a dll for me!


Well since I had luck getting that to compile I'm gonna try to create a new dll pascal project and just import the autoassembler + assembler and try to copy those few needed functions from CEFuncProc or wherever and see if I can get a standalone dll to compile!

Am I doing it the right way or is there already a simple way to compile a ceautoassembler dll from the latest CE and with aobscan and exactly how it works in CE?

Will post back if I run into errors or issues I need help with, or if I'm succesfull! Smile Thanks!

P.S. Oh and I don't think I need to mention it, but just to be clear any trainers I would make with this would be released 100% for free here on CEF itself, I would never even attempt to try and profit of of any of CE's code... Even after I have re-written it in C++ form still to me I would still consider it CE's code as I would be translating it from pascal code to c++ code... I imagine someday soon an AutoAssembler class (no dll necessary Very Happy now that would be great)



AutoAssemblerDll.png
 Description:
 Filesize:  115.15 KB
 Viewed:  24580 Time(s)

AutoAssemblerDll.png



_________________
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Oct 07, 2012 1:10 pm    Post subject: Reply with quote

That define was used to make it easier to make a dll, but it hasn't been used in a long time
Also, i recommend removing the lua includes and lua functionality, else you'll end up with the whole cheat engine program as a dll

This means modifications to the symbolhandler as well

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

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

Joined: 02 Sep 2012
Posts: 323

PostPosted: Tue Oct 16, 2012 2:45 am    Post subject: Alright, have made good progress... Reply with quote

Alright, i've been slowly working on this a little bit each day throughout the week and this morning I pushed on fixing errors, recompiling, fixing more errors, and so on! I got to a point now however, which I'm not sure how to continue...

I think I fixed almost all errors if not all, but now its giving me some strange errors which I cant seem to get past... even after reading about a solution online I dont really understand it... (after including 'Interfaces' in uses as suggested online[uses basically like include files in c/c++] I get another error: "cannot find unit Interfaces used by standaloneassembler check if package LCL is in the dependencies)

I'm not sure how to check if LCL is in the dependencies, and even if it isnt and I add it, is that really what I need, this dll isn't supposed to have a gui only the functionality...

Look at the images and the actual project called 'standaloneassembler' I've attached to see what I mean... (which should've been called 'standaloneautoassembler' because it aims to include the 'auto' part of it too, but oh well)

Project includes these files (commented out/ changed around/ attempted to get compiling without screwing it up to not work):

autoassembler, Assemblerunit, symbolhandler, symbollisthandler, simpleaobscanner, memscan, foundlisthelper, and CEAutoAssemblerFuncProc

CEAutoAssemblerFuncProc is a really slimmed down version of CEFuncProc which is just supposed to include only the bare minimum functionality from CEFuncProc as necessary for just the auto assembler to work...

Oh yeah and I did remove all the lua bits! it could be slimmed down more, but I was just trying to get it to compile and then to actually work after that...

Well thanks for your help so far, but still its not quite there yet! Confused

Here's the project file to check out how far I got (cant post zips): http://www.sendspace.com/file/tbrg9h
or
http://depositfiles.com/files/a764lw2wd



C++AutoAssembler-errors-im-not-sure-how-to-fix.png
 Description:
 Filesize:  91.37 KB
 Viewed:  24133 Time(s)

C++AutoAssembler-errors-im-not-sure-how-to-fix.png



C++AutoAssembler-almost-fully-compiling.png
 Description:
 Filesize:  359.51 KB
 Viewed:  24133 Time(s)

C++AutoAssembler-almost-fully-compiling.png



_________________
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Wed Oct 17, 2012 10:41 am    Post subject: Reply with quote

in project->inspector make sure that vcl is in the list. if not add it.

As for gui dependencies, if forms, or dialogs is included in the uses list, then gui objects are included as well. And dialogs is used to display error messages

Also, begin/end is only executed on process dll attach. Thread attaches are done internally (example: threadvar variable )

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

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

Joined: 02 Sep 2012
Posts: 323

PostPosted: Thu Oct 18, 2012 4:50 pm    Post subject: Reply with quote

Dark Byte wrote:
in project->inspector make sure that vcl is in the list. if not add it.

As for gui dependencies, if forms, or dialogs is included in the uses list, then gui objects are included as well. And dialogs is used to display error messages

Also, begin/end is only executed on process dll attach. Thread attaches are done internally (example: threadvar variable )


Ah yes since the error messages are displayed through dialogs, the gui objects need to be included as well, I wasn't thinking of that! Thanks for pointing that out...

Alright I went to project inspector added 'LCL' as a new requirement, 'LCLBase' was already there and after interfaces was added to uses, it compiled successfully and built standaloneassembler.dll Very Happy So apparently I did get through all the errors, though there is a new problem now!

The compiled dll does not seem to want to be loaded! I'm attempting to dynamically load it and GetProcAddress to find the address to the exported 'AutoAssembleIt' function...

I can''t even get to the point to use GetProcAddress because I don't get a valid handle to the module when calling LoadLibrary on it... checking with CE I can see the dll isn't loaded when trying to goto address and use its name example 'standaloneassembler.dll'

The C/C++ dll I've created to test it loads fine itself...

I suspect the problem is that DllMain for the pascal dll is not returning true/1 so its failing to attach... (If you return 0 on DllMain the dll wont be loaded, and exports cannot be accessed)

This one seems silly and I feel stupid now, there must be an easy way to make sure the pascal dll is returning 1 on DllMain... It's probably obvious too I just can't seem to figure it out!

Trying to do a 'Result:=1' or 'Result:=true' between the begin and end. block says Result is undefined, when normally Result is the return value whatever type it may be.

Also for some reason the compiled dll is like 15.7MB not sure why its so large, but maybe that's not actually that big, not sure, regardless as long as it works I wouldn't care if its over 15 megs in size! As long as it works! lol

Here's the C++ dll I made which I can inject into a target process, then when it creates a thread and tries to load the standaloneautoassembler.dll (yes I've renamed it that and checked the file path it does exist at that correct path) it fails Confused

Code:

#include "Main.h"

HMODULE hMod;
char *TestScript = new char[1024];

typedef bool *(*AUTOASSEMBLE)(char *script, bool enabledisable);

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
   switch (dwReason)
   {
      case DLL_PROCESS_ATTACH:
         hMod = hModule;
         DisableThreadLibraryCalls(hMod);
         CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&AutoAssemblerTest, 0, 0, 0);
         break;
   }

   return TRUE; //Why isn't returning true for DllMain this straightforward in pascal?
}

void AutoAssemblerTest()
{
   char *Script = "[enable]\
               alloc(InfiniteMana,64)\
               label(ManaRet)\
               \
               InfiniteMana:\
               mov si,#1280\
               mov [ecx+4442],si\
               jmp ManaRet\
               \
               oni3.exe+1d9ed2:\
               jmp InfiniteMana\
               nop\
               nop\
               ManaRet:\
               \
               [disable]\
               \
               oni3.exe+1d9ed2:\
               add [ecx+4442],si\
               \
               dealloc(InfiniteMana)";

   ZeroMemory(TestScript,1024);
   strncpy(TestScript, Script, strlen(Script));

   OutputDebugString(L"About to load Auto Assembler Dll...");

   HMODULE AutoAssemblerDll = LoadLibrary(L"C:\\lazarus\\Projects\\standaloneassembler\\standaloneautoassembler.dll");

   if(AutoAssemblerDll)
   {
      OutputDebugString(L"Successfully loaded the AA dll...");

      AUTOASSEMBLE AutoAssemble = (AUTOASSEMBLE)GetProcAddress(AutoAssemblerDll, "AutoAssembleIt");

      if(AutoAssemble)
      {
         OutputDebugString(L"Successfully got function address of \"AutoAssembleIt\"");
   
         bool Result = AutoAssemble(TestScript, 1);

         if(Result)
            OutputDebugString(L"It Worked! :D");
      }
   }
   
   delete[] TestScript;
}


Thanks again for all your help! At least I'm through all the compiling errors now I just need to get it to load properly so I can test whether I broke anything with all the commenting out and changing around!

- Steve

_________________
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Thu Oct 18, 2012 6:36 pm    Post subject: Reply with quote

Don't bother about dllmain, that is all done for you (you can override it, but it's not needed, or recommended)
use getlasterror to see why it fails.
The most common reason is that your C program is 32-bit and you're using the 64-bit freepascal, or the other way around

Also, you're using the LoadLibrary call instead of explicitly saying LoadLibraryA or LoadLibraryW. Depending on your compiler settings this decides if it's going to pass the widestring pointer to LoadLibraryA or LoadLibraryW

And make sure you have actually exported the function (don't just add exports behind the function declaration)
Use a pe header inspector to see if it actually exports anything. (ce has one)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source 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