Skip to content

MASTG-TOOL-0135: PlistBuddy

O PlistBuddy está disponível no macOS e permite imprimir e modificar arquivos .plist. Ele não está no PATH padrão, mas pode ser executado via /usr/libexec/PlistBuddy. O PlistBuddy usa uma sintaxe personalizada para executar comandos no arquivo plist fornecido.

Imprimindo um Arquivo Plist

O exemplo abaixo imprime uma representação ASCII do arquivo Info.plist do iOS UnCrackable Nível 1 especificando o comando Print:

/usr/libexec/PlistBuddy -c "Print" Info.plist
Dict {
    DTXcode = 0821
    DTSDKName = iphoneos10.2
    CFBundleName = UnCrackable Level 1
    UILaunchStoryboardName = LaunchScreen
    CFBundleIcons~ipad = Dict {
        CFBundlePrimaryIcon = Dict {
            CFBundleIconFiles = Array {
                AppIcon-120x20
                AppIcon-129x29
                AppIcon-140x40
                AppIcon-157x57
                AppIcon-160x60
                AppIcon-150x50
                AppIcon-172x72
                AppIcon-176x76
                AppIcon-183.5x83.5
            }
        }
    }
    DTSDKBuild = 14C89
    CFBundleDevelopmentRegion = en
    CFBundleVersion = 1
    BuildMachineOSBuild = 15G1212
    DTPlatformName = iphoneos
    CFBundleShortVersionString = 1.0
    UIMainStoryboardFile = Main
    CFBundleSupportedPlatforms = Array {
        iPhoneOS
    }
    CFBundlePackageType = APPL
    CFBundleInfoDictionaryVersion = 6.0
    UIRequiredDeviceCapabilities = Array {
        armv7
    }
    CFBundleExecutable = UnCrackable Level 1
    DTCompiler = com.apple.compilers.llvm.clang.1_0
    UISupportedInterfaceOrientations~ipad = Array {
        UIInterfaceOrientationPortrait
        UIInterfaceOrientationPortraitUpsideDown
        UIInterfaceOrientationLandscapeLeft
        UIInterfaceOrientationLandscapeRight
    }
    CFBundleIdentifier = sg.vp.UnCrackable1
    MinimumOSVersion = 8.0
    DTXcodeBuild = 8C1002
    DTPlatformVersion = 10.2
    LSRequiresIPhoneOS = true
    UISupportedInterfaceOrientations = Array {
        UIInterfaceOrientationPortrait
        UIInterfaceOrientationLandscapeLeft
        UIInterfaceOrientationLandscapeRight
    }
    CFBundleDisplayName = UnCrackable1
    CFBundleIcons = Dict {
        CFBundlePrimaryIcon = Dict {
            CFBundleIconFiles = Array {
                AppIcon-120x20
                AppIcon-129x29
                AppIcon-140x40
                AppIcon-157x57
                AppIcon-160x60
            }
        }
    }
    UIDeviceFamily = Array {
        1
        2
    }
    DTPlatformBuild = 14C89
}

Você também pode imprimir entradas específicas. Propriedades de dicionário são especificadas via : e índices de array são baseados em 0. O comando abaixo imprime o terceiro formato de ícone do aplicativo:

/usr/libexec/PlistBuddy -c "Print CFBundleIcons~ipad:CFBundlePrimaryIcon:CFBundleIconFiles:2" Info.plist
AppIcon-140x40

Alterando Valores do Plist

O PlistBuddy também pode alterar valores via comando Set <chave> <valor>. O exemplo a seguir atualiza o CFBundleDisplayName:

/usr/libexec/PlistBuddy -c "Set CFBundleDisplayName 'My New App Name'" Info.plist
/usr/libexec/PlistBuddy -c "Print CFBundleDisplayName" Info.plist
My New App Name

Adicionando e Excluindo Valores do Plist

Entradas podem ser adicionadas e excluídas especificando a chave, valor e tipo:

/usr/libexec/PlistBuddy -c "Add CustomDictionary dict" Info.plist
/usr/libexec/PlistBuddy -c "Add CustomDictionary:CustomProperty string 'OWASP MAS'" Info.plist
/usr/libexec/PlistBuddy -c "Print CustomDictionary" Info.plist
Dict {
    CustomProperty = OWASP MAS
}