<commit_before>//
//  $Id: //depot/InjectionPluginLite/Classes/BundleInjection.h#19 $
//  Injection
//
//  Created by <NAME> on 16/01/2012.
//  Copyright (c) 2012 <NAME>. All rights reserved.
//
//  Client application interface to Code Injection system.
//  Added to program's main.m to connect to the Injection app.
//
//  This file is copyright and may not be re-distributed, whole or in part.
//

#import "BundleInterface.h"

#define INJECTION_PORT 31442
#define INJECTION_MAGIC -INJECTION_PORT*INJECTION_PORT
#define INJECTION_APPNAME "Injection"
#define INJECTION_MKDIR -1
#define INJECTION_NOFILE -2
#define INJECTION_CLOSE -3

#ifdef DEBUG
#define INLog NSLog
#else
#define INLog if(0) NSLog
#endif

struct _in_header { int pathLength, dataLength; };

@interface BundleInjection : NSObject
+ (BOOL)readHeader:(struct _in_header *)header forPath:(char *)path from:(int)fdin;
+ (BOOL)writeBytes:(off_t)bytes withPath:(const char *)path from:(int)fdin to:(int)fdout;
#ifdef INJECTION_BUNDLE
+ (void)loadedClass:(Class)newClass notify:(BOOL)notify;
+ (void)loadedNotify:(BOOL)notify;
#endif
@end


#import <netinet/tcp.h>
#import <arpa/inet.h>
#import <sys/stat.h>
#import <unistd.h>
#import <fcntl.h>

#ifndef INJECTION_NOIMPL

#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
@implementation UIAlertView(Injection)
- (void)injectionDismiss {
    [self dismissWithClickedButtonIndex:0 animated:YES];
}
@end
#endif

@interface BundleInjection(Private)
- (void)bundleLoader;
- (void)loadBundle;
@end

@implementation BundleInjection

+ (BOOL)readHeader:(struct _in_header *)header forPath:(char *)path from:(int)fdin {
    return read( fdin, header, sizeof *header ) == sizeof *header &&
        read( fdin, path, header->pathLength ) == header->pathLength;
}

+ (BOOL)writeBytes:(off_t)bytes withPath:(const char *)path from:(int)fdin to:(int)fdout {
    BOOL ok = 1;
    if ( path ) {
        struct _in_header header;
        header.pathLength = (int)strlen( path )+1;
        header.dataLength = (int)bytes;
        ok = ok && write( fdout, &header, sizeof header ) == sizeof header &&
            write( fdout, path, header.pathLength ) == header.pathLength;<commit_msg>resolve forward reference<commit_after>//
//  $Id: //depot/InjectionPluginLite/Classes/BundleInjection.h#20 $
//  Injection
//
//  Created by <NAME> on 16/01/2012.
//  Copyright (c) 2012 <NAME>. All rights reserved.
//
//  Client application interface to Code Injection system.
//  Added to program's main.m to connect to the Injection app.
//
//  This file is copyright and may not be re-distributed, whole or in part.
//

#import "BundleInterface.h"

#define INJECTION_PORT 31442
#define INJECTION_MAGIC -INJECTION_PORT*INJECTION_PORT
#define INJECTION_APPNAME "Injection"
#define INJECTION_MKDIR -1
#define INJECTION_NOFILE -2
#define INJECTION_CLOSE -3

#ifdef DEBUG
#define INLog NSLog
#else
#define INLog if(0) NSLog
#endif

struct _in_header { int pathLength, dataLength; };

@interface BundleInjection : NSObject
+ (BOOL)readHeader:(struct _in_header *)header forPath:(char *)path from:(int)fdin;
+ (BOOL)writeBytes:(off_t)bytes withPath:(const char *)path from:(int)fdin to:(int)fdout;
#ifdef INJECTION_BUNDLE
+ (void)loadedClass:(Class)newClass notify:(BOOL)notify;
+ (void)loadedNotify:(BOOL)notify;
#endif
@end


#import <netinet/tcp.h>
#import <arpa/inet.h>
#import <sys/stat.h>
#import <unistd.h>
#import <fcntl.h>

#ifndef INJECTION_NOIMPL

#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
@interface UINib(BundleInjection)
- (NSArray *)inInstantiateWithOwner:(id)ownerOrNil options:(NSDictionary *)optionsOrNil;
@end
@implementation UIAlertView(Injection)
- (void)injectionDismiss {
    [self dismissWithClickedButtonIndex:0 animated:YES];
}
@end
#endif

@interface BundleInjection(Private)
- (void)bundleLoader;
- (void)loadBundle;
@end

@implementation BundleInjection

+ (BOOL)readHeader:(struct _in_header *)header forPath:(char *)path from:(int)fdin {
    return read( fdin, header, sizeof *header ) == sizeof *header &&
        read( fdin, path, header->pathLength ) == header->pathLength;
}

+ (BOOL)writeBytes:(off_t)bytes withPath:(const char *)path from:(int)fdin to:(int)fdout {
    BOOL ok = 1;
    if ( path ) {
        struct _in_header header;
        header.pathLength = (int)strlen( path )+1;
        header.dataLength = (int)bytes;
        ok = ok && write( fdout, &header, sizeof header ) == sizeof header &&
            write( fdout, path, header.pathLength ) == header.pathLength;
{'fraction_non_alphanumeric': 0.13092046470062557, 'fraction_numerical': 0.01161751563896336, 'mean_word_length': 4.769329896907217, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4033153', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1519, 'n_words': 380}