Page 1 of 1

Custom convention support in TypeManager.create_type_from_dict

Posted: Mon Apr 24, 2017 10:54 am
by iPlayer
Hey there,

Is there any built-in mechanism to specify custom conventions that will be used when parsing data in TypeManager.create_type_from_dict/create_type_from_file?

Say, I've got the following file

Syntax: Select all

[function]

# CTFGameRules::GetPayloadToBlock
[[get_payload_to_block]]
identifier_windows =
identifier_linux = _ZNK12CTFGameRules17GetPayloadToBlockEi
convention = MY_CALLING_CONVENTION
arguments_windows = POINTER, INT
arguments_linux = POINTER, POINTER, INT

I'd like to pass somewhere a dict like

Syntax: Select all

{'MY_CALLING_CONVENTION': MyCallingConvention}

to get the function built with that convention.

So far the only possibility I've found is to:
1. Subclass memory.helpers.Key and override its as_convention method;
2. Subclass memory.manager.TypeManager and override its create_type_from_dict method so that it will use my own Key class instead of the stock one.

But create_type_from_dict is way too big. Copy-pasting it only to replace all Key occurrences seems dumb to me.

Re: Custom convention support in TypeManager.create_type_from_dict

Posted: Mon Apr 24, 2017 11:26 am
by iPlayer
For now I will override TypeManager.function to replace convention in case it is Convention.CUSTOM and will define conventions I need as CUSTOM in the ini-file. This limits me to one custom convention per one TypeManager. Luckily I only need one.

Syntax: Select all

class PLRTypeManager(TypeManager):
def function(
self, identifier, args=(), return_type=DataType.VOID,
convention=Convention.THISCALL, doc=None):

if convention == Convention.CUSTOM:
convention = _GetPayloadConvention

return super().function(identifier, args, return_type, convention, doc)

Re: Custom convention support in TypeManager.create_type_from_dict

Posted: Mon Apr 24, 2017 7:11 pm
by Ayuto