Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwj committed Jun 12, 2014
0 parents commit ba26b8a
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/
110 changes: 110 additions & 0 deletions main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
yololib
Inject dylibs into existing Mach-O binaries
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
*/

#include <stdio.h>
#include <string.h>
#include <mach-o/fat.h>
#include <mach-o/loader.h>
#import <Foundation/Foundation.h>

NSString* DYLIB_PATH;

//#define DYLIB_PATH "@executable_path/crack.dylib"
#define DYLIB_CURRENT_VER 0x10000
#define DYLIB_COMPATIBILITY_VERSION 0x10000


#define swap32(value) (((value & 0xFF000000) >> 24) | ((value & 0x00FF0000) >> 8) | ((value & 0x0000FF00) << 8) | ((value & 0x000000FF) << 24) )
#define ARMV7 9
#define ARMV6 6

void inject_dylib(FILE* newFile, uint32_t top) {
fseek(newFile, top, SEEK_SET);
struct mach_header mach;

fread(&mach, sizeof(struct mach_header), 1, newFile);

NSData* data = [DYLIB_PATH dataUsingEncoding:NSUTF8StringEncoding];

uint32_t dylib_size = (uint32_t)[data length] + sizeof(struct dylib_command);
dylib_size += sizeof(long) - (dylib_size % sizeof(long)); // load commands like to be aligned by long

mach.ncmds += 1;
uint32_t sizeofcmds = mach.sizeofcmds;
mach.sizeofcmds += dylib_size;

fseek(newFile, -sizeof(struct mach_header), SEEK_CUR);
fwrite(&mach, sizeof(struct mach_header), 1, newFile);
printf("Patching mach_header..\n");

fseek(newFile, sizeofcmds, SEEK_CUR);

struct dylib_command dyld;
fread(&dyld, sizeof(struct dylib_command), 1, newFile);

printf("Attaching dylib..\n\n");

dyld.cmd = LC_LOAD_DYLIB;
dyld.cmdsize = dylib_size;
dyld.dylib.compatibility_version = DYLIB_COMPATIBILITY_VERSION;
dyld.dylib.current_version = DYLIB_CURRENT_VER;
dyld.dylib.timestamp = 2;
dyld.dylib.name.offset = sizeof(struct dylib_command);
fseek(newFile, -sizeof(struct dylib_command), SEEK_CUR);

fwrite(&dyld, sizeof(struct dylib_command), 1, newFile);

fwrite([data bytes], [data length], 1, newFile);

}
int main(int argc, const char * argv[])
{
char buffer[4096], binary[4096], dylib[4096];

strlcpy(binary, argv[1], sizeof(binary));
strlcpy(dylib, argv[2], sizeof(dylib));
DYLIB_PATH = [NSString stringWithFormat:@"@executable_path/%@", [NSString stringWithUTF8String:dylib]];
NSLog(@"dylib path %@", DYLIB_PATH);
FILE *binaryFile = fopen(binary, "r+");
printf("Reading binary: %s\n\n", binary);
fread(&buffer, sizeof(buffer), 1, binaryFile);

struct fat_header* fh = (struct fat_header*) (buffer);


if (fh->magic == FAT_CIGAM) {
struct fat_arch* arch = (struct fat_arch*) &fh[1];
printf("FAT binary!\n");
int i;
for (i = 0; i < swap32(fh->nfat_arch); i++) {
printf("Injecting to arch %i\n", swap32(arch->cpusubtype));
inject_dylib(binaryFile, swap32(arch->offset));
arch++;
}
}
else {
printf("Thin binary!\n");
inject_dylib(binaryFile, 0);
}
printf("Complete!\n");
return 0;
}

218 changes: 218 additions & 0 deletions yololib.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
AD4A0D571949A42E00B6B127 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD4A0D561949A42E00B6B127 /* Foundation.framework */; };
AD4A0D591949AA5B00B6B127 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = AD4A0D581949AA5B00B6B127 /* main.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
AD49F4E31769B63900B8D2E0 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
AD49F4E51769B63A00B8D2E0 /* yololib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = yololib; sourceTree = BUILT_PRODUCTS_DIR; };
AD4A0D561949A42E00B6B127 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
AD4A0D581949AA5B00B6B127 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
AD49F4E21769B63900B8D2E0 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
AD4A0D571949A42E00B6B127 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
AD49F4DC1769B63800B8D2E0 = {
isa = PBXGroup;
children = (
AD4A0D581949AA5B00B6B127 /* main.m */,
AD4A0D561949A42E00B6B127 /* Foundation.framework */,
AD49F4E61769B63A00B8D2E0 /* Products */,
);
sourceTree = "<group>";
};
AD49F4E61769B63A00B8D2E0 /* Products */ = {
isa = PBXGroup;
children = (
AD49F4E51769B63A00B8D2E0 /* yololib */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
AD49F4E41769B63900B8D2E0 /* yololib */ = {
isa = PBXNativeTarget;
buildConfigurationList = AD49F4EE1769B63A00B8D2E0 /* Build configuration list for PBXNativeTarget "yololib" */;
buildPhases = (
AD49F4E11769B63900B8D2E0 /* Sources */,
AD49F4E21769B63900B8D2E0 /* Frameworks */,
AD49F4E31769B63900B8D2E0 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = yololib;
productName = yololib;
productReference = AD49F4E51769B63A00B8D2E0 /* yololib */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
AD49F4DD1769B63800B8D2E0 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0460;
ORGANIZATIONNAME = test;
};
buildConfigurationList = AD49F4E01769B63900B8D2E0 /* Build configuration list for PBXProject "yololib" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = AD49F4DC1769B63800B8D2E0;
productRefGroup = AD49F4E61769B63A00B8D2E0 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
AD49F4E41769B63900B8D2E0 /* yololib */,
);
};
/* End PBXProject section */

/* Begin PBXSourcesBuildPhase section */
AD49F4E11769B63900B8D2E0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
AD4A0D591949AA5B00B6B127 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
AD49F4EC1769B63A00B8D2E0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.9;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
AD49F4ED1769B63A00B8D2E0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.9;
SDKROOT = macosx;
};
name = Release;
};
AD49F4EF1769B63A00B8D2E0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
AD49F4F01769B63A00B8D2E0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
AD49F4E01769B63900B8D2E0 /* Build configuration list for PBXProject "yololib" */ = {
isa = XCConfigurationList;
buildConfigurations = (
AD49F4EC1769B63A00B8D2E0 /* Debug */,
AD49F4ED1769B63A00B8D2E0 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
AD49F4EE1769B63A00B8D2E0 /* Build configuration list for PBXNativeTarget "yololib" */ = {
isa = XCConfigurationList;
buildConfigurations = (
AD49F4EF1769B63A00B8D2E0 /* Debug */,
AD49F4F01769B63A00B8D2E0 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = AD49F4DD1769B63800B8D2E0 /* Project object */;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba26b8a

Please sign in to comment.