1

One of the third-party binary libraries I'm using has an unfortunate NSLog statement that I'd like to avoid at runtime (it leaks personal information). The framework developer is unwilling to change this line and I have no alternatives (binary patching is not an option, nor switching providers).

Is it possible to define my own NSLog symbol that I could use to filter out the unwanted logging and delegate other logging calls to the original NSLog? Would Apple reject an app that overrides core framework symbols?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
slipheed
  • 7,170
  • 3
  • 27
  • 38
  • 1
    Yes it's possible, just use the same definition as the system one. Since NSLog is a variadic function (accepting varying number of args) you'll probably need something like NSLogv in your overriding implementation. Is the framework a dylib or a static library linked with your app binary? Overriding NSLog will work in the latter case only. As a last resort you could totally silence NSLog http://stackoverflow.com/a/12611692/5329717 – Kamil.S Apr 12 '17 at 17:09
  • @Kamil.S why only a comment? Just add a little more information, preferably a code sample and this looks like a great answer! – Losiowaty Apr 12 '17 at 17:16

1 Answers1

2

Yes it is. You can put this code in any of your .m files, but I recommend AppDelegate.

// Objective-C code
void NSLog(NSString *format, ...) {

    //You'll probably want some logic here to determine the issuer of NSLog
    //and silence it(aka return) if necessary

    va_list args;
    va_start(args, format);
    NSLogv(format, args);
    va_end(args);
}

Overriding NSLog will only work if the framework is not a dylib. As a last resort you could totally silence NSLog by redirecting stderr stackoverflow.com/a/12611692/5329717

Community
  • 1
  • 1
Kamil.S
  • 5,205
  • 2
  • 22
  • 51