]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/lib/reqdumper.h
2 * Copyright (c) 2006-2007,2011 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 // reqdumper - Requirement un-parsing (disassembly)
30 #include "reqreader.h"
35 namespace CodeSigning
{
39 // A decompiler for (compiled) requirements programs.
40 // This is intended to produce compiler-ready source, and the
41 // (decompile . compile) cycle is meant to be loss-less.
43 // Note that a Dumper is a type of Interpreter, so it can use the program stream
44 // accessors of the Interpreter. However, the evaluaton Context is absent, so
45 // actual validation functions must not be called.
47 class Dumper
: public Requirement::Reader
{
49 explicit Dumper(const Requirement
*req
, bool debug
= false)
50 : Reader(req
), mDebug(debug
) { }
53 slPrimary
, // syntax primary
56 slTop
// where we start
59 void dump(); // decompile this (entire) requirement
60 void expr(SyntaxLevel level
= slTop
); // decompile one requirement expression
62 std::string
value() const { return mOutput
; }
63 operator std::string () const { return value(); }
65 typedef unsigned char Byte
;
69 static string
dump(const Requirements
*reqs
, bool debug
= false);
70 static string
dump(const Requirement
*req
, bool debug
= false);
71 static string
dump(const BlobCore
*req
, bool debug
= false); // dumps either
75 isSimple
, // printable and does not require quotes
76 isPrintable
, // can be quoted safely
77 isBinary
// contains binary bytes (use 0xnnn form)
79 void data(PrintMode bestMode
= isSimple
, bool dotOkay
= false);
81 void dotString() { data(isSimple
, true); }
82 void quotedString() { data(isPrintable
); }
83 void hashData(); // H"bytes"
84 void certSlot(); // symbolic certificate slot indicator (explicit)
85 void match(); // a match suffix (op + value)
87 void print(const char *format
, ...) __attribute((format(printf
,2,3)));
90 void printBytes(const Byte
*data
, size_t length
); // just write hex bytes
93 std::string mOutput
; // output accumulator
94 bool mDebug
; // include debug output in mOutput
101 #endif //_H_REQDUMPER