Skip to content

Commit

Permalink
invoke method dialog. (todo: test it, and add a menu option for it in…
Browse files Browse the repository at this point in the history
… the popupmenu)
  • Loading branch information
cheat-engine committed May 23, 2017
1 parent a09e7e9 commit 10a7e6b
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 50 deletions.
57 changes: 57 additions & 0 deletions Cheat Engine/MonoDataCollector/MonoDataCollector/PipeServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ void CPipeServer::InitMono()


mono_signature_get_desc = (MONO_SIGNATURE_GET_DESC)GetProcAddress(hMono, "mono_signature_get_desc");
mono_signature_get_params = (MONO_SIGNATURE_GET_PARAMS)GetProcAddress(hMono, "mono_signature_get_params");
mono_signature_get_param_count = (MONO_SIGNATURE_GET_PARAM_COUNT)GetProcAddress(hMono, "mono_signature_get_param_count");
mono_signature_get_return_type = (MONO_SIGNATURE_GET_RETURN_TYPE)GetProcAddress(hMono, "mono_signature_get_return_type");

Expand Down Expand Up @@ -645,6 +646,58 @@ void CPipeServer::DisassembleMethod()
g_free(disassembly);
}

void CPipeServer::GetMethodParameters()
{
void *method = (void *)ReadQword();
void *methodsignature = mono_method_signature(method);
int i;

if (methodsignature)
{
int paramcount=mono_signature_get_param_count(methodsignature);
char **names = (char **)calloc(sizeof(char *), paramcount);
mono_method_get_param_names(method, (const char **)names);
WriteByte(paramcount);
for (i = 0; i < paramcount; i++)
{
if (names[i])
{
WriteByte(strlen(names[i]));
Write(names[i], strlen(names[i]));
}
else
WriteByte(0);
}

//param types
{
gpointer iter = NULL;
MonoType *paramtype=mono_signature_get_params((MonoMethodSignature*)methodsignature, &iter);

if (paramtype)
WriteDword(mono_type_get_type(paramtype));
else
WriteDword(0);
}

{
MonoType *returntype = mono_signature_get_return_type(methodsignature);
if (returntype)
WriteDword(mono_type_get_type(returntype));
else
WriteDword(0);
}






}
else
WriteByte(0);
}

void CPipeServer::GetMethodSignature()
{
void *method = (void *)ReadQword();
Expand Down Expand Up @@ -1155,6 +1208,10 @@ void CPipeServer::Start(void)
DisassembleMethod();
break;

case MONOCMD_GETMETHODPARAMETERS:
GetMethodParameters();
break;

case MONOCMD_GETMETHODSIGNATURE:
GetMethodSignature();
break;
Expand Down
10 changes: 8 additions & 2 deletions Cheat Engine/MonoDataCollector/MonoDataCollector/PipeServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@
#define MONOCMD_OBJECT_NEW 33
#define MONOCMD_OBJECT_INIT 34
#define MONOCMD_GETVTABLEFROMCLASS 35
#define MONOCMD_GETMETHODPARAMETERS 36


typedef struct MonoType;
typedef struct MonoMethodSignature;
typedef void * gpointer;

typedef void (__cdecl *MonoDomainFunc) (void *domain, void *user_data);
typedef void (__cdecl *GFunc) (void *data, void *user_data);
Expand Down Expand Up @@ -120,8 +123,9 @@ typedef void* (__cdecl *MONO_METHOD_HEADER_GET_CODE)(void *methodheader, UINT32
typedef char* (__cdecl *MONO_DISASM_CODE)(void *dishelper, void *method, void *ip, void *end);

typedef char* (__cdecl *MONO_SIGNATURE_GET_DESC)(void *signature, int include_namespace);
typedef MonoType* (__cdecl *MONO_SIGNATURE_GET_PARAMS)(MonoMethodSignature *sig, gpointer *iter);
typedef int (__cdecl *MONO_SIGNATURE_GET_PARAM_COUNT)(void *signature);
typedef void* (__cdecl *MONO_SIGNATURE_GET_RETURN_TYPE)(void *signature);
typedef MonoType* (__cdecl *MONO_SIGNATURE_GET_RETURN_TYPE)(void *signature);


typedef void* (__cdecl *MONO_IMAGE_RVA_MAP)(void *image, UINT32 addr);
Expand Down Expand Up @@ -224,6 +228,7 @@ class CPipeServer : Pipe
MONO_METHOD_GET_PARAM_NAMES mono_method_get_param_names;

MONO_SIGNATURE_GET_DESC mono_signature_get_desc;
MONO_SIGNATURE_GET_PARAMS mono_signature_get_params;
MONO_SIGNATURE_GET_PARAM_COUNT mono_signature_get_param_count;
MONO_SIGNATURE_GET_RETURN_TYPE mono_signature_get_return_type;

Expand Down Expand Up @@ -290,6 +295,7 @@ class CPipeServer : Pipe
void FreeMethod();
void DisassembleMethod();
void GetMethodSignature();
void GetMethodParameters();
void GetParentClass();
void GetVTableFromClass();
void GetStaticFieldAddressFromClass();
Expand Down
Loading

0 comments on commit 10a7e6b

Please sign in to comment.