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 3609832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:40:38+00:00 2026-05-18T21:40:38+00:00

So, I’m messing around with some interposing code on OSX (gcc 4.2.1) and I’m

  • 0

So, I’m messing around with some interposing code on OSX (gcc 4.2.1) and I’m trying to get the following to work:

When I call ./login using the DYLD_INSERT_LIBRARIES=my.dylib, it should override the default login implementation and use my custom implementation. Granted this is a contrived example, but its just to help me understand the point.

My source:

cat libinterposers.c

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "login.h"

typedef struct interpose_s
{
  void *new_func;
  void *orig_func;
} interpose_t;

int my_open(const char *, int, mode_t);
int my_close(int);
int my_login();


static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) = 
{
     { (void *)my_open,  (void *)open  },
     { (void *)my_close, (void *)close },
     { (void *)my_login, (void *)login },
};

int my_login()
{
  printf("--> my_login()\n");
  return 1;
}

int my_open(const char *path, int flags, mode_t mode)
{
  int ret = open(path, flags, mode);
  printf("--> %d = open(%s, %x, %x)\n", ret, path, flags, mode);
  return ret;
}

int my_close(int d)
{
  int ret = close(d);
  printf("--> %d = close(%d)\n", ret, d);
  return ret;
}

cat login.c

#include <stdio.h>
#include "login.h"

int login()
{
  return -1;
}

int main()
{
  if (login() == 1)
  {
    printf("login successful\n");
  }
  else
  {
    printf("login failed\n");
  }
}

And finally, login.h

int login();

Now when I execute with something like “cat /dev/null” it works fine …

DYLD_INSERT_LIBRARIES=/tmp/libinterposers.dylib cat /dev/null
--> 3 = open(/dev/null, 0, 0)
--> 0 = close(3

However, when I run with my ./login example

DYLD_INSERT_LIBRARIES=/tmp/libinterposers.dylib ./login
login failed

As you can see, it just prints login failed, my custom “my_login” function never runs … any ideas? Thanks in advance!

  • 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-05-18T21:40:39+00:00Added an answer on May 18, 2026 at 9:40 pm

    Your login function is linked statically, not dynamically, so there’s nothing to interpose. You can’t interpose statically linked functions. If you want this to work, you’ll need to move login to its own dynamic library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker

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.