Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:51:47+00:00 2026-06-05T09:51:47+00:00

I want to hook a function called png_handle_IHDR declared locally in the ImageIO framework.

  • 0

I want to hook a function called png_handle_IHDR declared locally in the ImageIO framework. I used MobileSafari as the filter. But while calling the original function, mobilesafari crashes. Upon inspection of the NSLog, i get this:

Jun  5 17:21:08 unknown MobileSafari[553] <Warning>: dlopen ImageIO success!
Jun  5 17:21:08 unknown MobileSafari[553] <Warning>: Zeroing of nlist success!
Jun  5 17:21:08 unknown MobileSafari[553] <Warning>: method name successfully assigned!
Jun  5 17:21:08 unknown MobileSafari[553] <Warning>: nlist SUCCESS! nlsetting..
Jun  5 17:21:08 unknown MobileSafari[553] <Warning>: nlset success! Hooking..
Jun  5 17:21:09 unknown MobileSafari[553] <Warning>: Png IHDR handle hooking!
Jun  5 17:21:09 unknown UIKitApplication:com.apple.mobilesafari[0x819][553] <Notice>: libpng error: Invalid IHDR chunk
Jun  5 17:21:09 unknown ReportCrash[554] <Notice>: Formulating crash report for process MobileSafari[553]
Jun  5 17:21:09 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.apple.mobilesafari[0x819]) Job appears to have crashed: Abort trap: 6
Jun  5 17:21:09 unknown SpringBoard[530] <Warning>: Application 'Safari' exited abnormally with signal 6: Abort trap: 6

I immediately gathered that its very likely that I got the function prototype of the png_handle_IHDR wrong. The following is my code in the tweak:

#import <CoreFoundation/CoreFoundation.h>
#include <substrate.h>

#define ImageIO "/System/Library/Frameworks/ImageIO.framework/ImageIO"

void (*png_handle_IHDR)();

MSHook(void, png_handle_IHDR){
    NSLog(@"Png IHDR handle hooking!\n");
    _png_handle_IHDR(); //crashed here!!
    NSLog(@"Png IHDR handle hooking finished!\n");

}

template <typename Type_>
static void nlset(Type_ &function, struct nlist *nl, size_t index) {
    struct nlist &name(nl[index]);
    uintptr_t value(name.n_value);
    if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
        value |= 0x00000001;
    function = reinterpret_cast<Type_>(value);
}

MSInitialize {

        if (dlopen(ImageIO, RTLD_LAZY | RTLD_NOLOAD)!=NULL)
        {       
                NSLog(@"dlopen ImageIO success!\n");
                struct nlist nl[2];
                bzero(&nl, sizeof(nl));
                NSLog(@"Zeroing of nlist success!\n");
                nl[0].n_un.n_name = (char*) "_png_handle_IHDR"; 
                NSLog(@"method name successfully assigned!\n");
                nlist(ImageIO,nl);
                NSLog(@"nlist SUCCESS! nlsetting..\n");
                nlset(png_handle_IHDR, nl, 0);  
                NSLog(@"nlset success! Hooking..\n");
                MSHookFunction(png_handle_IHDR,MSHake(png_handle_IHDR));
        }        
}

My makefile is as such:

include theos/makefiles/common.mk

TWEAK_NAME = privateFunctionTest
privateFunctionTest_FILES = Tweak.xm

include $(THEOS_MAKE_PATH)/tweak.mk
privateFunctionTest_FRAMEWORKS = UIKit ImageIO CoreGraphics Foundation CoreFoundation

Edit: The question is, is knowing the original function arguments necessary for a successful hook? If yes, is getting the function prototype from the disassembly the only way? There is no definition of this in any of the SDK headers. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:51:48+00:00Added an answer on June 5, 2026 at 9:51 am

    Ok, I decompiled the function and get the function prototype guessed by the decompiler. As long as the parameters and return type broadly matched e.g. bool : int, unsigned int : int, it still works without killing the execution. So this works:

    int *png_handle_IHDR(int a1, int a2, int a3);
    
    MSHook(int, png_handle_IHDR, int a1, int a2, int a3){
    
        NSLog(@"png_handle_IHDR(%d,%d,%d)", a1,a2,a3);
        int val = _png_handle_IHDR(a1,a2,a3);
        NSLog(@"Png IHDR handle hooking finished, returning %d as result!", val);
        return val;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a hook method which gets called everytime any function of
Want to use signal when follow() function called in UserProfile. I've written signal which
I have a class of div MyClass I want to hook up to two
How does drupal create its own hook. Similarly i want a customized hook for
I want to have a Mercurial hook that will run before committing a transaction
I am writing a pre-commit hook. I want to run php -l against all
I'm trying to create a hook in one Wordpress plugin that could be used
I want this function to compile the contents of the current buffer(a C file)
I want to redirect my form after submissions, I'm trying to use a hook,
Basically I want to create a custom handler to unserialize a db field called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.