Skip to content

Commit ba26b8a

Browse files
committed
initial commit
0 parents  commit ba26b8a

File tree

5 files changed

+361
-0
lines changed

5 files changed

+361
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Xcode
2+
#
3+
build/
4+
*.pbxuser
5+
!default.pbxuser
6+
*.mode1v3
7+
!default.mode1v3
8+
*.mode2v3
9+
!default.mode2v3
10+
*.perspectivev3
11+
!default.perspectivev3
12+
xcuserdata
13+
*.xccheckout
14+
*.moved-aside
15+
DerivedData
16+
*.hmap
17+
*.ipa
18+
*.xcuserstate
19+
20+
# CocoaPods
21+
#
22+
# We recommend against adding the Pods directory to your .gitignore. However
23+
# you should judge for yourself, the pros and cons are mentioned at:
24+
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
25+
#
26+
# Pods/

main.m

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
yololib
3+
Inject dylibs into existing Mach-O binaries
4+
5+
6+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
7+
Version 2, December 2004
8+
9+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
10+
11+
Everyone is permitted to copy and distribute verbatim or modified
12+
copies of this license document, and changing it is allowed as long
13+
as the name is changed.
14+
15+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
16+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
17+
18+
0. You just DO WHAT THE FUCK YOU WANT TO.
19+
20+
*/
21+
22+
#include <stdio.h>
23+
#include <string.h>
24+
#include <mach-o/fat.h>
25+
#include <mach-o/loader.h>
26+
#import <Foundation/Foundation.h>
27+
28+
NSString* DYLIB_PATH;
29+
30+
//#define DYLIB_PATH "@executable_path/crack.dylib"
31+
#define DYLIB_CURRENT_VER 0x10000
32+
#define DYLIB_COMPATIBILITY_VERSION 0x10000
33+
34+
35+
#define swap32(value) (((value & 0xFF000000) >> 24) | ((value & 0x00FF0000) >> 8) | ((value & 0x0000FF00) << 8) | ((value & 0x000000FF) << 24) )
36+
#define ARMV7 9
37+
#define ARMV6 6
38+
39+
void inject_dylib(FILE* newFile, uint32_t top) {
40+
fseek(newFile, top, SEEK_SET);
41+
struct mach_header mach;
42+
43+
fread(&mach, sizeof(struct mach_header), 1, newFile);
44+
45+
NSData* data = [DYLIB_PATH dataUsingEncoding:NSUTF8StringEncoding];
46+
47+
uint32_t dylib_size = (uint32_t)[data length] + sizeof(struct dylib_command);
48+
dylib_size += sizeof(long) - (dylib_size % sizeof(long)); // load commands like to be aligned by long
49+
50+
mach.ncmds += 1;
51+
uint32_t sizeofcmds = mach.sizeofcmds;
52+
mach.sizeofcmds += dylib_size;
53+
54+
fseek(newFile, -sizeof(struct mach_header), SEEK_CUR);
55+
fwrite(&mach, sizeof(struct mach_header), 1, newFile);
56+
printf("Patching mach_header..\n");
57+
58+
fseek(newFile, sizeofcmds, SEEK_CUR);
59+
60+
struct dylib_command dyld;
61+
fread(&dyld, sizeof(struct dylib_command), 1, newFile);
62+
63+
printf("Attaching dylib..\n\n");
64+
65+
dyld.cmd = LC_LOAD_DYLIB;
66+
dyld.cmdsize = dylib_size;
67+
dyld.dylib.compatibility_version = DYLIB_COMPATIBILITY_VERSION;
68+
dyld.dylib.current_version = DYLIB_CURRENT_VER;
69+
dyld.dylib.timestamp = 2;
70+
dyld.dylib.name.offset = sizeof(struct dylib_command);
71+
fseek(newFile, -sizeof(struct dylib_command), SEEK_CUR);
72+
73+
fwrite(&dyld, sizeof(struct dylib_command), 1, newFile);
74+
75+
fwrite([data bytes], [data length], 1, newFile);
76+
77+
}
78+
int main(int argc, const char * argv[])
79+
{
80+
char buffer[4096], binary[4096], dylib[4096];
81+
82+
strlcpy(binary, argv[1], sizeof(binary));
83+
strlcpy(dylib, argv[2], sizeof(dylib));
84+
DYLIB_PATH = [NSString stringWithFormat:@"@executable_path/%@", [NSString stringWithUTF8String:dylib]];
85+
NSLog(@"dylib path %@", DYLIB_PATH);
86+
FILE *binaryFile = fopen(binary, "r+");
87+
printf("Reading binary: %s\n\n", binary);
88+
fread(&buffer, sizeof(buffer), 1, binaryFile);
89+
90+
struct fat_header* fh = (struct fat_header*) (buffer);
91+
92+
93+
if (fh->magic == FAT_CIGAM) {
94+
struct fat_arch* arch = (struct fat_arch*) &fh[1];
95+
printf("FAT binary!\n");
96+
int i;
97+
for (i = 0; i < swap32(fh->nfat_arch); i++) {
98+
printf("Injecting to arch %i\n", swap32(arch->cpusubtype));
99+
inject_dylib(binaryFile, swap32(arch->offset));
100+
arch++;
101+
}
102+
}
103+
else {
104+
printf("Thin binary!\n");
105+
inject_dylib(binaryFile, 0);
106+
}
107+
printf("Complete!\n");
108+
return 0;
109+
}
110+

yololib.xcodeproj/project.pbxproj

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
AD4A0D571949A42E00B6B127 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD4A0D561949A42E00B6B127 /* Foundation.framework */; };
11+
AD4A0D591949AA5B00B6B127 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = AD4A0D581949AA5B00B6B127 /* main.m */; };
12+
/* End PBXBuildFile section */
13+
14+
/* Begin PBXCopyFilesBuildPhase section */
15+
AD49F4E31769B63900B8D2E0 /* CopyFiles */ = {
16+
isa = PBXCopyFilesBuildPhase;
17+
buildActionMask = 2147483647;
18+
dstPath = /usr/share/man/man1/;
19+
dstSubfolderSpec = 0;
20+
files = (
21+
);
22+
runOnlyForDeploymentPostprocessing = 1;
23+
};
24+
/* End PBXCopyFilesBuildPhase section */
25+
26+
/* Begin PBXFileReference section */
27+
AD49F4E51769B63A00B8D2E0 /* yololib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = yololib; sourceTree = BUILT_PRODUCTS_DIR; };
28+
AD4A0D561949A42E00B6B127 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
29+
AD4A0D581949AA5B00B6B127 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
30+
/* End PBXFileReference section */
31+
32+
/* Begin PBXFrameworksBuildPhase section */
33+
AD49F4E21769B63900B8D2E0 /* Frameworks */ = {
34+
isa = PBXFrameworksBuildPhase;
35+
buildActionMask = 2147483647;
36+
files = (
37+
AD4A0D571949A42E00B6B127 /* Foundation.framework in Frameworks */,
38+
);
39+
runOnlyForDeploymentPostprocessing = 0;
40+
};
41+
/* End PBXFrameworksBuildPhase section */
42+
43+
/* Begin PBXGroup section */
44+
AD49F4DC1769B63800B8D2E0 = {
45+
isa = PBXGroup;
46+
children = (
47+
AD4A0D581949AA5B00B6B127 /* main.m */,
48+
AD4A0D561949A42E00B6B127 /* Foundation.framework */,
49+
AD49F4E61769B63A00B8D2E0 /* Products */,
50+
);
51+
sourceTree = "<group>";
52+
};
53+
AD49F4E61769B63A00B8D2E0 /* Products */ = {
54+
isa = PBXGroup;
55+
children = (
56+
AD49F4E51769B63A00B8D2E0 /* yololib */,
57+
);
58+
name = Products;
59+
sourceTree = "<group>";
60+
};
61+
/* End PBXGroup section */
62+
63+
/* Begin PBXNativeTarget section */
64+
AD49F4E41769B63900B8D2E0 /* yololib */ = {
65+
isa = PBXNativeTarget;
66+
buildConfigurationList = AD49F4EE1769B63A00B8D2E0 /* Build configuration list for PBXNativeTarget "yololib" */;
67+
buildPhases = (
68+
AD49F4E11769B63900B8D2E0 /* Sources */,
69+
AD49F4E21769B63900B8D2E0 /* Frameworks */,
70+
AD49F4E31769B63900B8D2E0 /* CopyFiles */,
71+
);
72+
buildRules = (
73+
);
74+
dependencies = (
75+
);
76+
name = yololib;
77+
productName = yololib;
78+
productReference = AD49F4E51769B63A00B8D2E0 /* yololib */;
79+
productType = "com.apple.product-type.tool";
80+
};
81+
/* End PBXNativeTarget section */
82+
83+
/* Begin PBXProject section */
84+
AD49F4DD1769B63800B8D2E0 /* Project object */ = {
85+
isa = PBXProject;
86+
attributes = {
87+
LastUpgradeCheck = 0460;
88+
ORGANIZATIONNAME = test;
89+
};
90+
buildConfigurationList = AD49F4E01769B63900B8D2E0 /* Build configuration list for PBXProject "yololib" */;
91+
compatibilityVersion = "Xcode 3.2";
92+
developmentRegion = English;
93+
hasScannedForEncodings = 0;
94+
knownRegions = (
95+
en,
96+
);
97+
mainGroup = AD49F4DC1769B63800B8D2E0;
98+
productRefGroup = AD49F4E61769B63A00B8D2E0 /* Products */;
99+
projectDirPath = "";
100+
projectRoot = "";
101+
targets = (
102+
AD49F4E41769B63900B8D2E0 /* yololib */,
103+
);
104+
};
105+
/* End PBXProject section */
106+
107+
/* Begin PBXSourcesBuildPhase section */
108+
AD49F4E11769B63900B8D2E0 /* Sources */ = {
109+
isa = PBXSourcesBuildPhase;
110+
buildActionMask = 2147483647;
111+
files = (
112+
AD4A0D591949AA5B00B6B127 /* main.m in Sources */,
113+
);
114+
runOnlyForDeploymentPostprocessing = 0;
115+
};
116+
/* End PBXSourcesBuildPhase section */
117+
118+
/* Begin XCBuildConfiguration section */
119+
AD49F4EC1769B63A00B8D2E0 /* Debug */ = {
120+
isa = XCBuildConfiguration;
121+
buildSettings = {
122+
ALWAYS_SEARCH_USER_PATHS = NO;
123+
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
124+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
125+
CLANG_CXX_LIBRARY = "libc++";
126+
CLANG_ENABLE_OBJC_ARC = YES;
127+
CLANG_WARN_CONSTANT_CONVERSION = YES;
128+
CLANG_WARN_EMPTY_BODY = YES;
129+
CLANG_WARN_ENUM_CONVERSION = YES;
130+
CLANG_WARN_INT_CONVERSION = YES;
131+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
132+
COPY_PHASE_STRIP = NO;
133+
GCC_C_LANGUAGE_STANDARD = gnu99;
134+
GCC_DYNAMIC_NO_PIC = NO;
135+
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
136+
GCC_OPTIMIZATION_LEVEL = 0;
137+
GCC_PREPROCESSOR_DEFINITIONS = (
138+
"DEBUG=1",
139+
"$(inherited)",
140+
);
141+
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
142+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
143+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
144+
GCC_WARN_UNINITIALIZED_AUTOS = YES;
145+
GCC_WARN_UNUSED_VARIABLE = YES;
146+
MACOSX_DEPLOYMENT_TARGET = 10.9;
147+
ONLY_ACTIVE_ARCH = YES;
148+
SDKROOT = macosx;
149+
};
150+
name = Debug;
151+
};
152+
AD49F4ED1769B63A00B8D2E0 /* Release */ = {
153+
isa = XCBuildConfiguration;
154+
buildSettings = {
155+
ALWAYS_SEARCH_USER_PATHS = NO;
156+
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
157+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
158+
CLANG_CXX_LIBRARY = "libc++";
159+
CLANG_ENABLE_OBJC_ARC = YES;
160+
CLANG_WARN_CONSTANT_CONVERSION = YES;
161+
CLANG_WARN_EMPTY_BODY = YES;
162+
CLANG_WARN_ENUM_CONVERSION = YES;
163+
CLANG_WARN_INT_CONVERSION = YES;
164+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
165+
COPY_PHASE_STRIP = YES;
166+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
167+
GCC_C_LANGUAGE_STANDARD = gnu99;
168+
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
169+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
170+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
171+
GCC_WARN_UNINITIALIZED_AUTOS = YES;
172+
GCC_WARN_UNUSED_VARIABLE = YES;
173+
MACOSX_DEPLOYMENT_TARGET = 10.9;
174+
SDKROOT = macosx;
175+
};
176+
name = Release;
177+
};
178+
AD49F4EF1769B63A00B8D2E0 /* Debug */ = {
179+
isa = XCBuildConfiguration;
180+
buildSettings = {
181+
CLANG_ENABLE_MODULES = YES;
182+
PRODUCT_NAME = "$(TARGET_NAME)";
183+
};
184+
name = Debug;
185+
};
186+
AD49F4F01769B63A00B8D2E0 /* Release */ = {
187+
isa = XCBuildConfiguration;
188+
buildSettings = {
189+
CLANG_ENABLE_MODULES = YES;
190+
PRODUCT_NAME = "$(TARGET_NAME)";
191+
};
192+
name = Release;
193+
};
194+
/* End XCBuildConfiguration section */
195+
196+
/* Begin XCConfigurationList section */
197+
AD49F4E01769B63900B8D2E0 /* Build configuration list for PBXProject "yololib" */ = {
198+
isa = XCConfigurationList;
199+
buildConfigurations = (
200+
AD49F4EC1769B63A00B8D2E0 /* Debug */,
201+
AD49F4ED1769B63A00B8D2E0 /* Release */,
202+
);
203+
defaultConfigurationIsVisible = 0;
204+
defaultConfigurationName = Release;
205+
};
206+
AD49F4EE1769B63A00B8D2E0 /* Build configuration list for PBXNativeTarget "yololib" */ = {
207+
isa = XCConfigurationList;
208+
buildConfigurations = (
209+
AD49F4EF1769B63A00B8D2E0 /* Debug */,
210+
AD49F4F01769B63A00B8D2E0 /* Release */,
211+
);
212+
defaultConfigurationIsVisible = 0;
213+
defaultConfigurationName = Release;
214+
};
215+
/* End XCConfigurationList section */
216+
};
217+
rootObject = AD49F4DD1769B63800B8D2E0 /* Project object */;
218+
}

yololib.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)