Jump to content

11 posts in this topic

Recommended Posts

Updated (edited)

Hello, in this tutorial I will show one of the ways to hook a function. I will be hooking a function from a Unity game.

First you need to find the address at which the beginning of the function is located in real time, this is difficult due to ASLR (address randomization).

First, let's write a method that will return the following address:

// RVA: 0x11FE288 Offset: 0x11FE288 VA: 0x11FE288
    private void Update() { }
  (This is the address and information about the function that is in the compiled game engine)

uint64_t getExecAddr(uint64_t addr, int index)
{
    const struct mach_header* header = _dyld_get_image_header(index);
    if (header == NULL){return 0;}

    uint64_t libLoadAddr = (uint64_t)header;
    uint64_t exec_addr = libLoadAddr + addr;

    return exec_addr;
}

In this example, we are making a method that returns a number of type uint64_t and takes two parameters: the address of the function (for example, the one I gave above) and the library index.

Using the _dyld_get_image_header() method, we get the address from which the library was loaded by its index.

 

How to find the library index? This can be done in two ways: Using the LLDB debugger (image list command) or using another method that we will now write (this method is better than the first one)

uint64_t getLibIndex(const char* que_image)
{
	int i = 0;
	int image_count = _dyld_image_count();

	for(; i < image_count; i++)
	{
		const char* req_image = _dyld_get_image_name(i);

		if(req_image && strcmp(req_image, que_image) == 0)
			{return i;}
	}
	return -1;
}

This method takes a path parameter to the library, we use the _dyld_image_count() method to find out how many libraries are loaded into the game process, then using a loop we compare our path to the library with others, and if the paths match, we return the index.

Okay, there's not much left. Now let's create a pointer to the old function and create a replacement function that will be called instead of the original one:

void (*old_Update)(void *self);

void Update(void *self)
{
 	// "your code here"
  
	old_Update(self);
}

Now let's just make a hook according to a template that can be easily found on the Internet:

%ctor 
{		
	MSHookFunction( (void *)address_to_your_func_with_aslr, (void *)Update, (void **)&old_Update);	
}	

To make it clearer, I will show the full code of my hook:

#include <unistd.h>
#include <dispatch/dispatch.h>
#include <mach-o/dyld.h>
#include <substrate.h>
#include <string.h>

uint64_t getExecAddr(uint64_t addr, int index)
{
    const struct mach_header* header = _dyld_get_image_header(index);
    if (header == NULL){return 0;}

    uint64_t libLoadAddr = (uint64_t)header;
    uint64_t exec_addr = libLoadAddr + addr;

    return exec_addr;
}


uint64_t getLibIndex(const char* que_image)
{
	int i = 0;
	int image_count = _dyld_image_count();

	for(; i < image_count; i++)
	{
		const char* req_image = _dyld_get_image_name(i);

		if(req_image && strcmp(req_image, que_image) == 0)
			{return i;}
	}
	return -1;
}


void (*old_Update)(void *self);

void Update(void *self)
{
	sleep(5);
	old_Update(self);
}


%ctor 
{	
	dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

		sleep(150);

		int index = getLibIndex("/private/var/containers/Bundle/Application/BAE27894-6809-4743-AFFA-C1F6B93195CB/hidenseek.app/Frameworks/UnityFramework.framework/UnityFramework");
		
		uint64_t address = getExecAddr(0x11fe288, index);

		MSHookFunction( (void *)address, (void *)Update, (void **)&old_Update);

	});	

}	

 

This is my test version of the hook, it works great. (dispatch_async I used to wait until all libraries are loaded) In my example, the hook changes the behavior of the program so that when Update() is called, the game slows down for 5 seconds, this is only a beta version and you can add other logic there :)

If you liked the tutorial, please rate it. I will try to answer questions :)

 

 

Updated by nngot44
  • Like 4
  • Thanks 1
  • Informative 1
Posted

Very good tutorial for beginner, easy to read and detailed

Thank you for posting

Posted
3 hours ago, nngot44 said:
/private/var/containers/Bundle/Application/BAE27894-6809-4743-AFFA-C1F6B93195CB/

Have to be careful here if you plan on releasing this tweak. :) This location is dynamic and changes per device & iOS version.

  • Informative 1
Posted
1 minute ago, 34306 said:

Really nice. Have you try this on Dopamine jailbreak? I got some issue while hooking on Dopamine.

 

What kind of issues? I've seen similar reports after converting rootful to rootless with iGameGod.

Posted
Just now, Rook said:

What kind of issues? I've seen similar reports after converting rootful to rootless with iGameGod.

I have no idea, maybe it's Dopamine issue. Opa said on 1.1 he fixed PPLRW but when i tried to hooking (Unity game). It still crash. I have no idea what's going on..
xVY8cNF.jpg

Posted
Just now, 34306 said:

I have no idea, maybe it's Dopamine issue. Opa said on 1.1 he fixed PPLRW but when i tried to hooking (Unity game). It still crash. I have no idea what's going on..
xVY8cNF.jpg

Shouldn't this be an ElleKit related issue rather than Dopamine?

I tried hooks on palera1n rootless and they seem to work fine.

Posted
Just now, Rook said:

Shouldn't this be an ElleKit related issue rather than Dopamine?

I tried hooks on palera1n rootless and they seem to work fine.

Let me update Ellekit. They already have Substitute, Substrate, Libhooker. And Ellekit such a weird thing...

Report back to you later!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below. For more information, please read our Posting Guidelines.
Reply to this topic... Posting Guidelines

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Our picks

    • Royal Kingdom v17659 +4 Jailed Cheats [ Coins + More ]
      Modded/Hacked App: Royal Kingdom By Dream Games
      Bundle ID: com.dreamgames.royalkingdom
      iTunes Store Link: https://apps.apple.com/ph/app/royal-kingdom/id1606549505
       

      Hack Features:
      - Freeze Coins
      - Freeze Lives
      - Freeze Boosters
      - Freeze Moves


      Jailbreak required hack(s): [Mod Menu Hack] Royal Kingdom v3987 +4 Cheats [ Unlimited Coins ] - Free Jailbroken Cydia Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 113 replies
    • Royal Kingdom v17659 +4 Cheats [ Coins + More ]
      Modded/Hacked App: Royal Kingdom By Dream Games
      Bundle ID: com.dreamgames.royalkingdom
      iTunes Store Link: https://apps.apple.com/ph/app/royal-kingdom/id1606549505
       

      Hack Features:
      - Freeze Coins
      - Freeze Lives
      - Freeze Boosters
      - Freeze Moves


      Non-Jailbroken & No Jailbreak required hack(s): [Non-Jailbroken Hack] Royal Kingdom v3987 +4 Jailed Cheats [ Unlimited Coins ] - Free Non-Jailbroken IPA Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 62 replies
    • Royal Match v28375 +10 Jailed Cheats [ Coins + More ]
      Modded/Hacked App: Royal Match By Dream Games Teknoloji Anonim Sirketi
      Bundle ID: com.dreamgames.royalmatch
      iTunes Store Link: https://apps.apple.com/us/app/royal-match/id1482155847?uo=4


      Mod Requirements:
      - Non-Jailbroken/Jailed or Jailbroken iPhone/iPad/iPod Touch.
      - Sideloadly / Cydia Impactor or alternatives.
      - A Computer Running Windows/macOS/Linux with iTunes installed.


      Hack Features:
      - Freeze Coins
      - Freeze Lives
      - Freeze Stars
      - Freeze Boosters
      - Freeze Time
      - Freeze Moves
      - Unlock VIP Badges
      - Unlock VIP Name Styles
      - Unlock VIP Frames
      - Auto Win -> Quit the level.


      Jailbreak required hack(s): [Mod Menu Hack] Royal Match v26455 +11 Cheats [ Unlimited Coins + More ] - Free Jailbroken Cydia Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 348 replies
    • Royal Match v28375 +10 Cheats [ Coins + More ]
      Modded/Hacked App: Royal Match By Dream Games Teknoloji Anonim Sirketi
      Bundle ID: com.dreamgames.royalmatch
      iTunes Store Link: https://apps.apple.com/us/app/royal-match/id1482155847?uo=4


      Mod Requirements:
      - Jailbroken iPhone/iPad/iPod Touch.
      - iGameGod / Filza / iMazing or any other file managers for iOS.
      - Cydia Substrate, ElleKit, Substitute or libhooker depending on your jailbreak.
      - PreferenceLoader (from Cydia, Sileo or Zebra).


      Hack Features:
      - Freeze Coins
      - Freeze Lives
      - Freeze Stars
      - Freeze Boosters
      - Freeze Time
      - Freeze Moves
      - Unlock VIP Badges
      - Unlock VIP Name Styles
      - Unlock VIP Frames
      - Auto Win -> Quit the level.


      Non-Jailbroken & No Jailbreak required hack(s): [IPA Mod Menu] Royal Match v26455 +11 Jailed Cheats [ Unlimited Coins + More ] - Free Non-Jailbroken IPA Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 449 replies
    • Three Kingdoms All-Star : Idle v1.2 +1 Jailed Cheat [ No Skill Cooldown ]
      Modded/Hacked App: Three Kingdoms All-Star : Idle By Highbrow
      Bundle ID: com.highbrow.games.tki
      iTunes Store Link: https://apps.apple.com/us/app/three-kingdoms-all-star-idle/id6737404289?uo=4

       


      🤩 Hack Features

      - No Skill Cooldown
      • 0 replies
    • Three Kingdoms All-Star : Idle v1.2 +1 Cheat [ No Skill Cooldown ]
      Modded/Hacked App: Three Kingdoms All-Star : Idle By Highbrow
      Bundle ID: com.highbrow.games.tki
      iTunes Store Link: https://apps.apple.com/us/app/three-kingdoms-all-star-idle/id6737404289?uo=4

       


      🤩 Hack Features

      - No Skill Cooldown
        • Winner
      • 2 replies
    • Adventure Bay - Farm Games v1.37.13 [ +4 Cheats ] Currency Max
      Modded/Hacked App: Adventure Bay - Farm Games By Gamegos Teknoloji A.S.
      Bundle ID: com.gamegos.adventure.bay.paradise.farm
      iTunes Store Link: https://apps.apple.com/us/app/adventure-bay-farm-games/id1578449819?uo=4
       

      🤩 Hack Features

      - Gems
      - Coins
      - Energy
      - Avatar Unlock
        • Like
      • 7 replies
    • Adventure Bay - Farm Games v1.37.13 [ +4 Jailed ] Currency Max
      Modded/Hacked App: Adventure Bay - Farm Games By Gamegos Teknoloji A.S.
      Bundle ID: com.gamegos.adventure.bay.paradise.farm
      iTunes Store Link: https://apps.apple.com/us/app/adventure-bay-farm-games/id1578449819?uo=4


      🤩 Hack Features

      - Gems
      - Coins
      - Energy
      - Avatar Unlock
        • Informative
        • Thanks
        • Winner
        • Like
      • 9 replies
    • Merge Cruise: Mystery Puzzle v0.36.140 [ +2 Cheats ] Currency Max
      Modded/Hacked App: Merge Cruise: Mystery Puzzle By STUDIO PEERPLAY GAMES LTD
      Bundle ID: com.peerplay.megamerge
      iTunes Store Link: https://apps.apple.com/us/app/merge-cruise-mystery-puzzle/id6459056553?uo=4
       

      🤩 Hack Features

      - Cash
      - Energy

      • 3 replies
    • Merge Cruise: Mystery Puzzle v0.36.140 [ +2 Jailed ] Currency Max
      Modded/Hacked App: Merge Cruise: Mystery Puzzle By STUDIO PEERPLAY GAMES LTD
      Bundle ID: com.peerplay.megamerge
      iTunes Store Link: https://apps.apple.com/us/app/merge-cruise-mystery-puzzle/id6459056553?uo=4
       

      🤩 Hack Features

      - Cash
      - Energy

        • Winner
        • Like
      • 5 replies
    • Turret Defense King v1.2.14 [ +9 Cheats ] Gold Max
      Modded/Hacked App: Turret Defense King By MOBIRIX
      Bundle ID: com.mobirix.tdwt
      iTunes Store Link: https://apps.apple.com/us/app/turret-defense-king/id6480586157?uo=4


      🚀 Hack Features

      - ADS NO [ Rewards Free]

      - Gold [ Revive To Get ]

      - Battle Coins [ Enemy Drop Kill ]

      - Tower Cost [ Earn Battle Coins ]

      - Enemy Max [ Only Stage Mod] Easy Win

      - Wave Max [ Only Stage Mod] Easy Win

      - Tower DMG [ Just Rebuild & Upgrade ]

      - Tower ATK Range

      - Tower Fire Rate
        • Agree
        • Winner
        • Like
      • 10 replies
    • Turret Defense King v1.2.14 [ +9 Jailed ] Gold Max
      Modded/Hacked App: Turret Defense King By MOBIRIX
      Bundle ID: com.mobirix.tdwt
      iTunes Store Link: https://apps.apple.com/us/app/turret-defense-king/id6480586157?uo=4


      🚀 Hack Features

      - ADS NO [ Rewards Free]

      - Gold [ Revive To Get ]

      - Battle Coins [ Enemy Drop Kill ]

      - Tower Cost [ Earn Battle Coins ]

      - Enemy Max [ Only Stage Mod] Easy Win

      - Wave Max [ Only Stage Mod] Easy Win

      - Tower DMG [ Just Rebuild & Upgrade ]

      - Tower ATK Range

      - Tower Fire Rate
        • Haha
        • Thanks
        • Winner
        • Like
      • 10 replies
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines