macOS Objective-C
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.
Objective-C
Caution
Objective-Cλ‘ μμ±λ νλ‘κ·Έλ¨μ Mach-O binariesλ‘ μ»΄νμΌλ λ ν΄λμ€ μ μΈμ μ μ§ν©λλ€. μ΄λ¬ν ν΄λμ€ μ μΈμλ λ€μμ μ΄λ¦κ³Ό μ νμ΄ ν¬ν¨λ©λλ€:
- ν΄λμ€
- ν΄λμ€ λ©μλ
- ν΄λμ€ μΈμ€ν΄μ€ λ³μ
μ΄ μ 보λ₯Ό class-dumpλ₯Ό μ¬μ©νμ¬ μ»μ μ μμ΅λλ€:
class-dump Kindle.app
μ΄ μ΄λ¦λ€μ μ΄μ§ νμΌμ 리λ²μ±μ λ μ΄λ ΅κ² λ§λ€κΈ° μν΄ λλ νλ μ μμ΅λλ€.
ν΄λμ€, λ©μλ λ° κ°μ²΄
μΈν°νμ΄μ€, μμ± λ° λ©μλ
// Declare the interface of the class
@interface MyVehicle : NSObject
// Declare the properties
@property NSString *vehicleType;
@property int numberOfWheels;
// Declare the methods
- (void)startEngine;
- (void)addWheels:(int)value;
@end
ν΄λμ€
@implementation MyVehicle : NSObject
// No need to indicate the properties, only define methods
- (void)startEngine {
NSLog(@"Engine started");
}
- (void)addWheels:(int)value {
self.numberOfWheels += value;
}
@end
κ°μ²΄ λ° λ©μλ νΈμΆ
ν΄λμ€μ μΈμ€ν΄μ€λ₯Ό μμ±νκΈ° μν΄ alloc λ©μλκ° νΈμΆλμ΄ κ° μμ±μ λν λ©λͺ¨λ¦¬λ₯Ό ν λΉνκ³ ν΄λΉ ν λΉμ μ λ‘λ‘ μ€μ ν©λλ€. κ·Έλ° λ€μ **init**μ΄ νΈμΆλμ΄ μμ±μ νμν κ°μΌλ‘ μ΄κΈ°νν©λλ€.
// Something like this:
MyVehicle *newVehicle = [[MyVehicle alloc] init];
// Which is usually expressed as:
MyVehicle *newVehicle = [MyVehicle new];
// To call a method
// [myClassInstance nameOfTheMethodFirstParam:param1 secondParam:param2]
[newVehicle addWheels:4];
ν΄λμ€ λ©μλ
ν΄λμ€ λ©μλλ μΈμ€ν΄μ€ λ©μλμ μ¬μ©λλ νμ΄ν (-) λμ νλ¬μ€ κΈ°νΈ (+)λ‘ μ μλ©λλ€. NSString ν΄λμ€ λ©μλ **stringWithString**μ κ°μ΄:
+ (id)stringWithString:(NSString *)aString;
Setter & Getter
μμ±μ μ€μ νκ³ κ°μ Έμ€κΈ° μν΄, μ νκΈ°λ²μ μ¬μ©νκ±°λ λ©μλλ₯Ό νΈμΆνλ κ²μ²λΌ ν μ μμ΅λλ€:
// Set
newVehicle.numberOfWheels = 2;
[newVehicle setNumberOfWheels:3];
// Get
NSLog(@"Number of wheels: %i", newVehicle.numberOfWheels);
NSLog(@"Number of wheels: %i", [newVehicle numberOfWheels]);
μΈμ€ν΄μ€ λ³μ
setter λ° getter λ©μλ λμ μΈμ€ν΄μ€ λ³μλ₯Ό μ¬μ©ν μ μμ΅λλ€. μ΄λ¬ν λ³μλ μμ±κ³Ό λμΌν μ΄λ¦μ κ°μ§μ§λ§ β_βλ‘ μμν©λλ€:
- (void)makeLongTruck {
_numberOfWheels = +10000;
NSLog(@"Number of wheels: %i", self.numberOfLeaves);
}
νλ‘ν μ½
νλ‘ν μ½μ λ©μλ μ μΈμ μ§ν©μ λλ€(μμ± μμ΄). νλ‘ν μ½μ ꡬννλ ν΄λμ€λ μ μΈλ λ©μλλ₯Ό ꡬνν©λλ€.
λ©μλλ νμμ μ νμ μ 2κ°μ§ μ νμ΄ μμ΅λλ€. κΈ°λ³Έμ μΌλ‘ λ©μλλ νμμ
λλ€(νμ§λ§ @required νκ·Έλ‘λ νμν μ μμ΅λλ€). λ©μλκ° μ νμ μμ λνλ΄λ €λ©΄ **@optional**μ μ¬μ©νμμμ€.
@protocol myNewProtocol
- (void) method1; //mandatory
@required
- (void) method2; //mandatory
@optional
- (void) method3; //optional
@end
λͺ¨λ ν¨κ»
// gcc -framework Foundation test_obj.m -o test_obj
#import <Foundation/Foundation.h>
@protocol myVehicleProtocol
- (void) startEngine; //mandatory
@required
- (void) addWheels:(int)value; //mandatory
@optional
- (void) makeLongTruck; //optional
@end
@interface MyVehicle : NSObject <myVehicleProtocol>
@property int numberOfWheels;
- (void)startEngine;
- (void)addWheels:(int)value;
- (void)makeLongTruck;
@end
@implementation MyVehicle : NSObject
- (void)startEngine {
NSLog(@"Engine started");
}
- (void)addWheels:(int)value {
self.numberOfWheels += value;
}
- (void)makeLongTruck {
_numberOfWheels = +10000;
NSLog(@"Number of wheels: %i", self.numberOfWheels);
}
@end
int main() {
MyVehicle* mySuperCar = [MyVehicle new];
[mySuperCar startEngine];
mySuperCar.numberOfWheels = 4;
NSLog(@"Number of wheels: %i", mySuperCar.numberOfWheels);
[mySuperCar setNumberOfWheels:3];
NSLog(@"Number of wheels: %i", mySuperCar.numberOfWheels);
[mySuperCar makeLongTruck];
}
κΈ°λ³Έ ν΄λμ€
λ¬Έμμ΄
// NSString
NSString *bookTitle = @"The Catcher in the Rye";
NSString *bookAuthor = [[NSString alloc] initWithCString:"J.D. Salinger" encoding:NSUTF8StringEncoding];
NSString *bookPublicationYear = [NSString stringWithCString:"1951" encoding:NSUTF8StringEncoding];
κΈ°λ³Έ ν΄λμ€λ λΆλ³νλ―λ‘ κΈ°μ‘΄ λ¬Έμμ΄μ λ¬Έμμ΄μ μΆκ°νλ €λ©΄ μ NSStringμ μμ±ν΄μΌ ν©λλ€.
NSString *bookDescription = [NSString stringWithFormat:@"%@ by %@ was published in %@", bookTitle, bookAuthor, bookPublicationYear];
λλ mutable λ¬Έμμ΄ ν΄λμ€λ₯Ό μ¬μ©ν μλ μμ΅λλ€:
NSMutableString *mutableString = [NSMutableString stringWithString:@"The book "];
[mutableString appendString:bookTitle];
[mutableString appendString:@" was written by "];
[mutableString appendString:bookAuthor];
[mutableString appendString:@" and published in "];
[mutableString appendString:bookPublicationYear];
λ²νΈ
// character literals.
NSNumber *theLetterZ = @'Z'; // equivalent to [NSNumber numberWithChar:'Z']
// integral literals.
NSNumber *fortyTwo = @42; // equivalent to [NSNumber numberWithInt:42]
NSNumber *fortyTwoUnsigned = @42U; // equivalent to [NSNumber numberWithUnsignedInt:42U]
NSNumber *fortyTwoLong = @42L; // equivalent to [NSNumber numberWithLong:42L]
NSNumber *fortyTwoLongLong = @42LL; // equivalent to [NSNumber numberWithLongLong:42LL]
// floating point literals.
NSNumber *piFloat = @3.141592654F; // equivalent to [NSNumber numberWithFloat:3.141592654F]
NSNumber *piDouble = @3.1415926535; // equivalent to [NSNumber numberWithDouble:3.1415926535]
// BOOL literals.
NSNumber *yesNumber = @YES; // equivalent to [NSNumber numberWithBool:YES]
NSNumber *noNumber = @NO; // equivalent to [NSNumber numberWithBool:NO]
λ°°μ΄, μ§ν© λ° μ¬μ
// Inmutable arrays
NSArray *colorsArray1 = [NSArray arrayWithObjects:@"red", @"green", @"blue", nil];
NSArray *colorsArray2 = @[@"yellow", @"cyan", @"magenta"];
NSArray *colorsArray3 = @[firstColor, secondColor, thirdColor];
// Mutable arrays
NSMutableArray *mutColorsArray = [NSMutableArray array];
[mutColorsArray addObject:@"red"];
[mutColorsArray addObject:@"green"];
[mutColorsArray addObject:@"blue"];
[mutColorsArray addObject:@"yellow"];
[mutColorsArray replaceObjectAtIndex:0 withObject:@"purple"];
// Inmutable Sets
NSSet *fruitsSet1 = [NSSet setWithObjects:@"apple", @"banana", @"orange", nil];
NSSet *fruitsSet2 = [NSSet setWithArray:@[@"apple", @"banana", @"orange"]];
// Mutable sets
NSMutableSet *mutFruitsSet = [NSMutableSet setWithObjects:@"apple", @"banana", @"orange", nil];
[mutFruitsSet addObject:@"grape"];
[mutFruitsSet removeObject:@"apple"];
// Dictionary
NSDictionary *fruitColorsDictionary = @{
@"apple" : @"red",
@"banana" : @"yellow",
@"orange" : @"orange",
@"grape" : @"purple"
};
// In dictionaryWithObjectsAndKeys you specify the value and then the key:
NSDictionary *fruitColorsDictionary2 = [NSDictionary dictionaryWithObjectsAndKeys:
@"red", @"apple",
@"yellow", @"banana",
@"orange", @"orange",
@"purple", @"grape",
nil];
// Mutable dictionary
NSMutableDictionary *mutFruitColorsDictionary = [NSMutableDictionary dictionaryWithDictionary:fruitColorsDictionary];
[mutFruitColorsDictionary setObject:@"green" forKey:@"apple"];
[mutFruitColorsDictionary removeObjectForKey:@"grape"];
λΈλ‘
λΈλ‘μ κ°μ²΄μ²λΌ λμνλ ν¨μλ‘, ν¨μμ μ λ¬λκ±°λ λ°°μ΄μ΄λ μ¬μ μ μ μ₯λ μ μμ΅λλ€. λν, κ°μ΄ μ£Όμ΄μ§λ©΄ κ°μ λνλΌ μ μμ΄ λλ€μ μ μ¬ν©λλ€.
returnType (^blockName)(argumentType1, argumentType2, ...) = ^(argumentType1 param1, argumentType2 param2, ...){
//Perform operations here
};
// For example
int (^suma)(int, int) = ^(int a, int b){
return a+b;
};
NSLog(@"3+4 = %d", suma(3,4));
ν¨μμμ λ§€κ°λ³μλ‘ μ¬μ©λ λΈλ‘ μ νμ μ μνλ κ²λ κ°λ₯ν©λλ€:
// Define the block type
typedef void (^callbackLogger)(void);
// Create a bloack with the block type
callbackLogger myLogger = ^{
NSLog(@"%@", @"This is my block");
};
// Use it inside a function as a param
void genericLogger(callbackLogger blockParam) {
NSLog(@"%@", @"This is my function");
blockParam();
}
genericLogger(myLogger);
// Call it inline
genericLogger(^{
NSLog(@"%@", @"This is my second block");
});
νμΌ
// Manager to manage files
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if file exists:
if ([fileManager fileExistsAtPath:@"/path/to/file.txt" ] == YES) {
NSLog (@"File exists");
}
// copy files
if ([fileManager copyItemAtPath: @"/path/to/file1.txt" toPath: @"/path/to/file2.txt" error:nil] == YES) {
NSLog (@"Copy successful");
}
// Check if the content of 2 files match
if ([fileManager contentsEqualAtPath:@"/path/to/file1.txt" andPath:@"/path/to/file2.txt"] == YES) {
NSLog (@"File contents match");
}
// Delete file
if ([fileManager removeItemAtPath:@"/path/to/file1.txt" error:nil]) {
NSLog(@"Removed successfully");
}
νμΌμ NSString κ°μ²΄ λμ NSURL κ°μ²΄λ₯Ό μ¬μ©νμ¬ κ΄λ¦¬νλ κ²λ κ°λ₯ν©λλ€. λ©μλ μ΄λ¦μ λΉμ·νμ§λ§ Path λμ **URL**μ μ¬μ©ν©λλ€.
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.


