2012-01-20 9 views
2

次のコードを使用して、アプリケーションが署名されていることを確認しています。これはObjective-Cにあり、Professional Cocoa Application Securityのコードに基づいています。Objective-CコードをプレーンCに変換する

OSStatus secError = noErr; 
// retrieve this process's code object 
SecCodeRef myCode; 
secError = SecCodeCopySelf(kSecCSDefaultFlags, &myCode); 
if (noErr != secError) 
{ 
    NSLog(@"unable to retrieve code object, security error %d", secError); 
    return -1; 
} 

// validate the process's identity, using the internal requirements 
secError = SecCodeCheckValidity(myCode, kSecCSDefaultFlags, NULL); 
switch (secError) 
{ 
    case noErr: 
     NSLog(@"this process has a valid signature"); 
     break; 
    case errSecCSUnsigned: 
     NSLog(@"this process executable is unsigned"); 
     break; 
    case errSecCSSignatureFailed: 
    case errSecCSGuestInvalid: 
     NSLog(@"this process has an invalid signature"); 
     break; 
    default: 
     NSLog(@"error %d validating signature", secError); 
     break; 
} 

// get the static code object, representing the executable on disk 
SecStaticCodeRef fileCode; 
secError = SecCodeCopyStaticCode(myCode, kSecCSDefaultFlags, &fileCode); 
if (noErr != secError) 
{ 
    NSLog(@"unable to get static code object, security error %d", secError); 
    CFRelease(myCode); 
    return -1; 
} 

//some basic information about the code signature 
NSDictionary *signingInfo = nil; 

secError = SecCodeCopySigningInformation(fileCode, kSecCSDefaultFlags, &signingInfo); 
if (noErr != secError) 
{ 
    if(secError == errSecCSSignatureFailed) 
     NSLog(@"invalid signature"); 
    else 
     NSLog(@"cannot get signing information, security error %d", secError); 
} 
else 
{ 
    NSLog(@"signing info: %@", signingInfo); 
    [signingInfo release]; 
} 

CFRelease(myCode); 
CFRelease(fileCode); 

私はまた、私は問題のC.一つで書いていますアプリにそれを使用することができますので、プレーンCにこれを変換するために、私はCFDictionaryRef *signingInfo = NULL;を使用することによって解決しようとしたNSDictionary *signingInfo = nil;される必要がありますが、それはしていません動作するようです。

誰でもこのコードをCに変換できますか?

ありがとうございます!

+0

ここで私たちは、ダウンワードをなぜ説明するのか気にしますか?あなたが何か言いたいことがあれば、私の顔に言ってください。ただdownvoteだけではありません –

+0

どうやって動かないのですか? – DanZimm

答えて

3

余分な*を使わずにCFDictionaryRef signingInfo = NULL;を試しましたか?コア基盤refはすでにポインタです。 CFDictionaryRefはフリーダイヤルでNSDictionary *に橋渡しされています。 [signingInfo release];CFRelease(signingInfo)に翻訳できます。また、NSLogを別のものに置き換える必要があります。

+0

すばらしい、ありがとう! 'CFRelease(signingInfo)'を指摘してくれてありがとう。 –

3

CFDictionaryRefはすでにポインタです。したがってCFDictionaryRef*ではなくCFDictionaryRefを使用してください。

関連する問題