forked from johnno1962/injectionforxcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevalCode.pl
More file actions
executable file
·165 lines (123 loc) · 5.15 KB
/
Copy pathevalCode.pl
File metadata and controls
executable file
·165 lines (123 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/perl -w
# $Id: //depot/injectionforxcode/InjectionPluginLite/evalCode.pl#3 $
# Injection
#
# Created by John Holdsworth on 16/01/2012.
# Copyright (c) 2012 John Holdsworth. All rights reserved.
#
# These files are copyright and may not be re-distributed, whole or in part.
#
use strict;
use FindBin;
use lib $FindBin::Bin;
use URI::Escape;
use common;
my ($pathID, $className, $isSwift, $code) = split /\^/, $selectedFile;
$className =~ s/^\w+\.//;
print "Searching logs in $logDir\n";
FOUND:
foreach my $log (split "\n", `ls -t "$logDir"/*.xcactivitylog`) {
foreach my $line ( split "\r", `gunzip <$log` ) {
if ( index( $line, " $arch" ) != -1 && $line =~ /XcodeDefault\.xctoolchain.+@{[$isSwift ?
" -primary-file " : " -c "]}("[^"]+\/$className\.(m|mm|swift)"|\S+\/$className\.(m|mm|swift))/ ) {
$selectedFile = $1;
$learnt = $line;
last FOUND;
}
}
}
if ( !$learnt ) {
print "Unkown class, using canned Objective-C compile..\n";
$isSwift = 0;
$selectedFile = "/tmp/injection_unknown.m";
chomp( $learnt = <<CANNED );
$xcodeApp/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch $arch -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -Wno-trigraphs -fpascal-strings -fobjc-arc -fmodules -O0 -Wno-missing-field-initializers -Wmissing-prototypes -Wno-implicit-atomic-properties -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -isysroot $xcodeApp/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -fexceptions -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch -mios-simulator-version-min=5.0 -c $selectedFile -o /tmp/injection_unknown.o
CANNED
open UNKNOWN, "> $selectedFile" or die "Could not open canned file.";
print UNKNOWN <<EMPTY;
\@import UIKit;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-property-synthesis"
#pragma clang diagnostic ignored "-Wincomplete-implementation"
#pragma clang diagnostic ignored "-Wprotocol"
\@implementation $className
+ (Class)class {
return self;
}
\@end
#pragma clang diagnostic pop
EMPTY
close UNKNOWN;
}
$selectedFile =~ s/["\\]//g;
$learnt =~ s/( -o .*?\.o).*/$1/g;
$code = uri_unescape( $code );
undef $/;
open SOURCE, $selectedFile or die "Could not read source: $selectedFile";
my $source = <SOURCE>;
my $additionsTag = "// added by XprobePlugin";
my ($swiftClass) = $source =~ /\@objc\(\w+\)\s+class (\w+)/;
$source =~ s@\n*$additionsTag.*|$@ $isSwift ? <<ENDSWIFT : <<ENDCODE @es;
$additionsTag
extension @{[$swiftClass||$className]} {
func xprint<T>(_ str: T) {
if let xprobe = NSClassFromString("Xprobe") {
#if swift(>=3.0)
Thread.detachNewThreadSelector(Selector(("xlog:")), toTarget:xprobe, with:"\\(str)" as NSString)
#else
NSThread.detachNewThreadSelector(Selector("xlog:"), toTarget:xprobe, withObject:"\\(str)" as NSString)
#endif
}
}
#if swift(>=3.0)
struct XprobeOutputStream: TextOutputStream {
var out = ""
mutating func write(_ string: String) {
out += string
}
}
func xdump<T>(_ arg: T) {
var stream = XprobeOutputStream()
dump(arg, to: &stream)
xprint(stream.out)
}
#endif
\@objc func onXprobeEval() {
$code
}
}
ENDSWIFT
$additionsTag
#ifdef DEBUG
\@interface NSObject(Xprobe)
+ (void)xlog:(NSString *)message;
\@end
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
static void XLog( NSString *format, ... ) {
va_list argp;
va_start(argp, format);
[NSClassFromString(@"Xprobe") xlog:[[NSString alloc] initWithFormat:format arguments:argp]];
}
static void xprint( const char *msg ) {
XLog( \@"Swift language used for Objective-C injection: %s", msg );
}
#pragma clang diagnostic pop
\@implementation $className(onXprobeEval)
- (void)onXprobeEval {
$code;
}
\@end
#endif
ENDCODE
print "!#$className $selectedFile\n";
open SOURCE, "> $selectedFile" or die "Could not write to source: $selectedFile";
print SOURCE $source;
close SOURCE;
my $INJECTION_NOTSILENT = 1<<2;
system "$FindBin::Bin/injectSource.pl",$resources, $workspace, $deviceRoot, $executable, $arch, $patchNumber, $flags&~$INJECTION_NOTSILENT, $unlockCommand, $addresses, $selectedFile, $xcodeApp, $buildRoot, $logDir, $learnt;
die if $? >> 8;
$source =~ s@\n*$additionsTag.*|$@\n@s;
open SOURCE, "> $selectedFile" or die "Could not write to source: $selectedFile";
print SOURCE $source;
close SOURCE;