-
-
Save CognitiveDisson/89e56dd3959225591df1469c1e958b8c to your computer and use it in GitHub Desktop.
Алгоритм генерации строки, которую хотим спрятать
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString*)hexStringFromString:(NSString*)string | |
{ | |
const char *utf8 = [string UTF8String]; | |
NSMutableString *result = [NSMutableString new]; | |
for (int i = 0; i < string.length; i++) { | |
[result appendFormat:@"0x%02X, ", *utf8++ & 0x00FF]; | |
} | |
return result; | |
} | |
- (void)printObfuscated { | |
unsigned char obfuscatedSecretKey[] = {0x6A, 0x6B, 0x4C, 0x6D, 0x33, 0x22, 0x66, 0x66}; | |
// Get the SHA1 of a class name, to form the obfuscator. | |
unsigned char obfuscator[CC_SHA1_DIGEST_LENGTH]; | |
NSData *className = [NSStringFromClass([RamblerResizerKeyProvider class]) | |
dataUsingEncoding:NSUTF8StringEncoding]; | |
CC_SHA1(className.bytes, (CC_LONG)className.length, obfuscator); | |
// XOR the class name against the obfuscated key, to form the real key. | |
unsigned char actualSecretKey[sizeof(obfuscatedSecretKey)]; | |
for (int i=0; i<sizeof(obfuscatedSecretKey); i++) { | |
// алгоритм модифифированный, добавлено i % sizeof(obfuscator) | |
// для того, чтобы пройтись по всему сообщению | |
actualSecretKey[i] = obfuscatedSecretKey[i] ^ obfuscator[i % sizeof(obfuscator)]; | |
} | |
NSData *identifier = [kRamblerResizerKeyIdentifier dataUsingEncoding:NSUTF8StringEncoding]; | |
CC_SHA1(identifier.bytes, (CC_LONG)className.length, obfuscator); | |
memcpy(obfuscatedSecretKey, actualSecretKey, sizeof(obfuscatedSecretKey)); | |
for (int i=0; i<sizeof(obfuscatedSecretKey); i++) { | |
// алгоритм модифифированный, добавлено i % sizeof(obfuscator) | |
// для того, чтобы пройтись по всему сообщению | |
actualSecretKey[i] = obfuscatedSecretKey[i] ^ obfuscator[i % sizeof(obfuscator)]; | |
} | |
for (int i=0; i<sizeof(obfuscatedSecretKey); i++) { | |
printf("0x%X ", actualSecretKey[i]); | |
} | |
} | |
- (NSString *)obtainKeyWithSeed:(NSString *)seed { | |
unsigned char obfuscatedKey[] = {0x51, 0xDD, 0xFF, 0x44, 0x3, 0xDC, 0xA9, 0xAB}; | |
unsigned char deobfuscatedKeyStage1[sizeof(obfuscatedKey)]; | |
deobfuscate(obfuscatedKey, | |
sizeof(obfuscatedKey), | |
NSStringFromClass([self class]), | |
deobfuscatedKeyStage1); | |
unsigned char deobfuscatedKeyStage2[sizeof(deobfuscatedKeyStage1)]; | |
deobfuscate(deobfuscatedKeyStage1, | |
sizeof(deobfuscatedKeyStage1), | |
seed, | |
deobfuscatedKeyStage2); | |
NSString *secret = [[NSString alloc] initWithBytes:deobfuscatedKeyStage2 | |
length:sizeof(deobfuscatedKeyStage2) | |
encoding:NSUTF8StringEncoding]; | |
return secret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment