BNM 2.4.0
 
Loading...
Searching...
No Matches
BNM Namespace Reference

Main BNM namespace. More...

Namespaces

namespace  ClassesManagement
 Namespace with some advanced APIs of ClassesManagement.
 
namespace  Coroutine
 Namespace that has types to create Unity coroutines.
 
namespace  Defaults
 Namespace that helps to get references to primitives and common used C# and Unity types.
 
namespace  Loading
 Namespace with all methods for loading BNM.
 
namespace  Operators
 Namespace that holds operators which may help with methods, events, fields and properties.
 
namespace  Types
 Namespace that holds C# primitives.
 
namespace  UnityEngine
 Namespace that has types and helpers to work with Unity objects.
 
namespace  Utils
 BNM namespace with utils.
 

Classes

struct  Class
 Class for working with il2cpp classes. More...
 
struct  CompileTimeClass
 Stores class info at compile time. More...
 
struct  CompileTimeClassBuilder
 Struct for building CompileTimeClass. More...
 
struct  Delegate
 Typed wrapper of Il2CppDelegate. More...
 
struct  DelegateBase
 Wrapper of Il2CppDelegate. More...
 
struct  Event
 Typed class for working with il2cpp events. More...
 
struct  EventBase
 Class base for working with il2cpp events. More...
 
struct  Exception
 Wrapper of Il2CppException. More...
 
struct  Field
 Typed class for working with il2cpp fields. More...
 
struct  FieldBase
 Class base for working with il2cpp fields. More...
 
struct  Image
 Class for working with il2cpp images. More...
 
struct  Method
 Typed class for working with il2cpp methods. More...
 
struct  MethodBase
 Class base for working with il2cpp methods. More...
 
struct  MulticastDelegate
 Typed wrapper of Il2CppMulticastDelegate. More...
 
struct  MulticastDelegateBase
 Wrapper of Il2CppMulticastDelegate. More...
 
struct  Property
 Typed class for working with il2cpp properties. More...
 
struct  PropertyBase
 Class base for working with il2cpp properties. More...
 

Typedefs

typedef Class LoadClass
 For people how love old BNM.
 
typedef IL2CPP::Il2CppReflectionType MonoType
 Redefinition of Il2CppReflectionType for shorter code.
 

Functions

template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool IsA (T object, IL2CPP::Il2CppClass *_class)
 Check if object is inherited from class.
 
template<>
bool IsA< IL2CPP::Il2CppObject * > (IL2CPP::Il2CppObject *object, IL2CPP::Il2CppClass *_class)
 Check if Il2CppObject is inherited from class.
 
template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool IsA (T object, Class _class)
 Check if object is inherited from class.
 
template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool IsA (T object, IL2CPP::Il2CppObject *_object)
 Check if object is inherited from object's class.
 
template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool IsA (T object, MonoType *_type)
 Check if object is inherited from object's class.
 
Exception TryInvoke (const std::function< void()> &func)
 Helper function for catching il2cpp errors.
 
bool InvokeHookImpl (IL2CPP::MethodInfo *info, void *newMet, void **oldMet)
 Hook method by changing MethodInfo.
 
template<typename T_NEW, typename T_OLD>
bool InvokeHook (const BNM::MethodBase &targetMethod, T_NEW newMet, T_OLD &oldMet)
 Hook method by changing MethodInfo.
 
template<typename T_NEW, typename T_OLD>
bool InvokeHook (const BNM::MethodBase &targetMethod, T_NEW newMet, T_OLD &&oldMet)
 Hook method by changing MethodInfo.
 
template<typename T_NEW, typename T_OLD>
bool InvokeHook (IL2CPP::MethodInfo *info, T_NEW newMet, T_OLD &oldMet)
 Hook method by changing MethodInfo.
 
template<typename T_NEW, typename T_OLD>
bool InvokeHook (IL2CPP::MethodInfo *info, T_NEW newMet, T_OLD &&oldMet)
 Hook method by changing MethodInfo.
 
bool VirtualHookImpl (BNM::Class targetClass, IL2CPP::MethodInfo *info, void *newMet, void **oldMet)
 Hook method by changing class virtual table.
 
template<typename T_NEW, typename T_OLD>
bool VirtualHook (BNM::Class targetClass, const BNM::MethodBase &targetMethod, T_NEW newMet, T_OLD &oldMet)
 Hook method by changing class virtual table.
 
template<typename T_NEW, typename T_OLD>
bool VirtualHook (BNM::Class targetClass, const BNM::MethodBase &targetMethod, T_NEW newMet, T_OLD &&oldMet)
 Hook method by changing class virtual table.
 
template<typename T_NEW, typename T_OLD>
bool VirtualHook (BNM::Class targetClass, IL2CPP::MethodInfo *info, T_NEW newMet, T_OLD &oldMet)
 Hook method by changing class virtual table.
 
template<typename T_NEW, typename T_OLD>
bool VirtualHook (BNM::Class targetClass, IL2CPP::MethodInfo *info, T_NEW newMet, T_OLD &&oldMet)
 Hook method by changing class virtual table.
 
template<typename NEW_T, typename T_OLD>
void BasicHook (const BNM::MethodBase &targetMethod, NEW_T newMethod, T_OLD &oldBytes)
 Hook method using hooking software.
 
template<typename NEW_T, typename T_OLD>
void BasicHook (const BNM::MethodBase &targetMethod, NEW_T newMethod, T_OLD &&oldBytes)
 Hook method using hooking software.
 
template<typename T>
bool CheckForNull (T obj)
 Macro function for checking pointer for null. Due to noinline attribute allows to check even this of objects.
 
template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool IsAllocated (T x)
 Macro function for checking if pointer points to valid address.
 
Structures::Mono::StringCreateMonoString (const std::string_view &str)
 Macro function for creating C# strings (BNM::Structures::Mono::String).
 
void * GetExternMethod (const std::string_view &str)
 Macro function for getting external methods (icall).
 
bool IsLoaded ()
 Check if BNM and il2cpp are loaded.
 
void * GetIl2CppLibraryHandle ()
 Get handle of libil2cpp.so if it's used by BNM.
 
template<typename T>
UnboxObject (T obj)
 Unbox any object.
 
bool AttachIl2Cpp ()
 Attach current thread to il2cpp VM.
 
IL2CPP::Il2CppThread * CurrentIl2CppThread ()
 Get current thread attached to il2cpp VM.
 
void DetachIl2Cpp ()
 Detach current thread from il2cpp VM.
 
void * Allocate (size_t size)
 Allocates memory that is registered in il2cpp's GC.
 
void Free (void *)
 Frees memory that was allocated by il2cpp.
 

Detailed Description

Main BNM namespace.

Function Documentation

◆ Allocate()

void * BNM::Allocate ( size_t size)

Allocates memory that is registered in il2cpp's GC.

Returns
Allocated memory

◆ AttachIl2Cpp()

bool BNM::AttachIl2Cpp ( )

Attach current thread to il2cpp VM.

Returns
True if thread was attached.

◆ BasicHook() [1/2]

template<typename NEW_T, typename T_OLD>
void BNM::BasicHook ( const BNM::MethodBase & targetMethod,
NEW_T newMethod,
T_OLD && oldBytes )

Hook method using hooking software.

Alias for BasicHook method

Parameters
targetMethodVirtual method info
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ BasicHook() [2/2]

template<typename NEW_T, typename T_OLD>
void BNM::BasicHook ( const BNM::MethodBase & targetMethod,
NEW_T newMethod,
T_OLD & oldBytes )

Hook method using hooking software.

Alias for BasicHook method

Parameters
targetMethodVirtual method info
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ CreateMonoString()

Structures::Mono::String * BNM::CreateMonoString ( const std::string_view & str)

Macro function for creating C# strings (BNM::Structures::Mono::String).

Returns
New mono string object

◆ CurrentIl2CppThread()

IL2CPP::Il2CppThread * BNM::CurrentIl2CppThread ( )

Get current thread attached to il2cpp VM.

Returns
IL2CPP::Il2CppThread if current tread is attached to VM, otherwise null.

◆ GetExternMethod()

void * BNM::GetExternMethod ( const std::string_view & str)

Macro function for getting external methods (icall).

Returns
Pointer to extern method if it's found, otherwise null.

◆ GetIl2CppLibraryHandle()

void * BNM::GetIl2CppLibraryHandle ( )

Get handle of libil2cpp.so if it's used by BNM.

Returns
Dlfcn handle of libil2cpp.so if it's used by BNM and BNM is loaded, otherwise null.

◆ InvokeHook() [1/4]

template<typename T_NEW, typename T_OLD>
bool BNM::InvokeHook ( const BNM::MethodBase & targetMethod,
T_NEW newMet,
T_OLD && oldMet )

Hook method by changing MethodInfo.

Alias for BNM::InvokeHookImpl

Parameters
targetMethodTarget method
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ InvokeHook() [2/4]

template<typename T_NEW, typename T_OLD>
bool BNM::InvokeHook ( const BNM::MethodBase & targetMethod,
T_NEW newMet,
T_OLD & oldMet )

Hook method by changing MethodInfo.

Alias for BNM::InvokeHookImpl

Parameters
targetMethodTarget method
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ InvokeHook() [3/4]

template<typename T_NEW, typename T_OLD>
bool BNM::InvokeHook ( IL2CPP::MethodInfo * info,
T_NEW newMet,
T_OLD && oldMet )

Hook method by changing MethodInfo.

Alias for BNM::InvokeHookImpl

Parameters
infoTarget method info
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ InvokeHook() [4/4]

template<typename T_NEW, typename T_OLD>
bool BNM::InvokeHook ( IL2CPP::MethodInfo * info,
T_NEW newMet,
T_OLD & oldMet )

Hook method by changing MethodInfo.

Alias for BNM::InvokeHookImpl

Parameters
infoTarget method info
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ InvokeHookImpl()

bool BNM::InvokeHookImpl ( IL2CPP::MethodInfo * info,
void * newMet,
void ** oldMet )

Hook method by changing MethodInfo.

This way of hooking will work only if method called using il2cpp API. There are not many such methods in Unity: All unity messages (like Start, Update etc.), some of system actions. Primary usage is Unity messages, because this way of hooking don't add any overhead, that basic hooks do.

Parameters
infoTarget method info
newMetPointer to replacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ IsA() [1/4]

template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool BNM::IsA ( T object,
Class _class )

Check if object is inherited from class.

Class is specified using BNM::Class

Parameters
objectAny pointer
_classBNM::Class
Template Parameters
TObject type
Returns
True if object is inherited from target class.

◆ IsA() [2/4]

template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool BNM::IsA ( T object,
IL2CPP::Il2CppClass * _class )

Check if object is inherited from class.

Class is specified using Il2CppClass.

Parameters
objectAny pointer
_classIl2CppClass pointer
Template Parameters
TObject type
Returns
True if object is inherited from target class.

◆ IsA() [3/4]

template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool BNM::IsA ( T object,
IL2CPP::Il2CppObject * _object )

Check if object is inherited from object's class.

Class is specified using object of target class.

Parameters
objectAny pointer
_objectIl2CppObject pointer
Template Parameters
TObject type
Returns
True if object is inherited from target class.

◆ IsA() [4/4]

template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool BNM::IsA ( T object,
MonoType * _type )

Check if object is inherited from object's class.

Class is specified using MonoType.

Parameters
objectAny pointer
_typeMonoType pointer
Template Parameters
TObject type
Returns
True if object is inherited from target type.

◆ IsA< IL2CPP::Il2CppObject * >()

template<>
bool BNM::IsA< IL2CPP::Il2CppObject * > ( IL2CPP::Il2CppObject * object,
IL2CPP::Il2CppClass * _class )

Check if Il2CppObject is inherited from class.

Parameters
objectIl2CppObject pointer
_classIl2CppClass pointer
Returns
True if Il2CppObject is inherited from target class.

◆ IsAllocated()

template<typename T, typename = std::enable_if<std::is_pointer<T>::value>>
bool BNM::IsAllocated ( T x)
inline

Macro function for checking if pointer points to valid address.

Returns
True if address is valid.

◆ IsLoaded()

bool BNM::IsLoaded ( )

Check if BNM and il2cpp are loaded.

Returns
True if BNM and il2cpp are loaded.

◆ TryInvoke()

Exception BNM::TryInvoke ( const std::function< void()> & func)

Helper function for catching il2cpp errors.

Parameters
funcFunction that can throw il2cpp exception
Returns
Valid exception if it's caught, otherwise empty exception.

◆ UnboxObject()

template<typename T>
T BNM::UnboxObject ( T obj)
inline

Unbox any object.

Returns
Unboxed object of passed type

◆ VirtualHook() [1/4]

template<typename T_NEW, typename T_OLD>
bool BNM::VirtualHook ( BNM::Class targetClass,
const BNM::MethodBase & targetMethod,
T_NEW newMet,
T_OLD && oldMet )

Hook method by changing class virtual table.

Alias for BNM::VirtualHookImpl

Parameters
targetClassTarget class
targetMethodVirtual method
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ VirtualHook() [2/4]

template<typename T_NEW, typename T_OLD>
bool BNM::VirtualHook ( BNM::Class targetClass,
const BNM::MethodBase & targetMethod,
T_NEW newMet,
T_OLD & oldMet )

Hook method by changing class virtual table.

Alias for BNM::VirtualHookImpl

Parameters
targetClassTarget class
targetMethodVirtual method
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ VirtualHook() [3/4]

template<typename T_NEW, typename T_OLD>
bool BNM::VirtualHook ( BNM::Class targetClass,
IL2CPP::MethodInfo * info,
T_NEW newMet,
T_OLD && oldMet )

Hook method by changing class virtual table.

Alias for BNM::VirtualHookImpl

Parameters
targetClassTarget class
infoVirtual method info
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ VirtualHook() [4/4]

template<typename T_NEW, typename T_OLD>
bool BNM::VirtualHook ( BNM::Class targetClass,
IL2CPP::MethodInfo * info,
T_NEW newMet,
T_OLD & oldMet )

Hook method by changing class virtual table.

Alias for BNM::VirtualHookImpl

Parameters
targetClassTarget class
infoVirtual method info
newMetReplacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if method valid

◆ VirtualHookImpl()

bool BNM::VirtualHookImpl ( BNM::Class targetClass,
IL2CPP::MethodInfo * info,
void * newMet,
void ** oldMet )

Hook method by changing class virtual table.

This way of hooking will work only if virtual method called from some method. This hook won't be triggered by overridden methods, because that methods call overridden method directly, without class virtual table.

Parameters
targetClassTarget class
infoVirtual method info
newMetPointer to replacement method
oldMetPointer where original method pointer will be stored. Can be null
Returns
True if class and method are valid and method got hooked