CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/exploits/CVE-2017-13861/liboffsetfinder64/img4.h
Views: 11784
1
//
2
// img4.h
3
// img4tool
4
//
5
// Created by tihmstar on 15.06.16.
6
// Copyright © 2016 tihmstar. All rights reserved.
7
//
8
9
#ifndef img4_h
10
#define img4_h
11
12
#ifdef __cplusplus
13
extern "C" {
14
#endif
15
16
#include <stdio.h>
17
//#include <plist/plist.h>
18
#define LEN_XTND 0x80 /* Indefinite or long form */
19
typedef unsigned char byte;
20
21
#define putStr(s,l) printf("%.*s",(int)l,s)
22
23
//TagClass
24
#define kASN1TagClassUniversal 0
25
#define kASN1TagClassApplication 1
26
#define kASN1TagClassContextSpecific 2
27
#define kASN1TagClassPrivate 3
28
29
//primitive
30
#define kASN1Primitive 0
31
#define kASN1Contructed 1
32
33
//tagNumber
34
#define kASN1TagEnd_of_Content 0
35
#define kASN1TagBOOLEAN 1
36
#define kASN1TagINTEGER 2
37
#define kASN1TagBIT 3
38
#define kASN1TagOCTET 4
39
#define kASN1TagNULL 5
40
#define kASN1TagOBJECT 6
41
#define kASN1TagObject 7
42
#define kASN1TagEXTERNAL 8
43
#define kASN1TagREAL 9
44
#define kASN1TagENUMERATED 10 //0x0A
45
#define kASN1TagEMBEDDED 11 //0x0B
46
#define kASN1TagUTF8String 12 //0x0C
47
#define kASN1TagRELATIVE_OID 13 //0x0D
48
#define kASN1TagReserved (14 | 15) //(0x0E | 0x0F)
49
#define kASN1TagSEQUENCE 16 //0x10
50
#define kASN1TagSET 17 //0x11
51
#define kASN1TagNumericString 18 //0x12
52
#define kASN1TagPrintableString 19 //0x13
53
#define kASN1TagT61String 20 //0x14
54
#define kASN1TagVideotexString 21 //0x15
55
#define kASN1TagIA5String 22 //0x16
56
#define kASN1TagUTCTime 23 //0x17
57
#define kASN1TagGeneralizedTime 24 //0x18
58
#define kASN1TagGraphicString 25 //0x19
59
#define kASN1TagVisibleString 26 //0x1A
60
#define kASN1TagGeneralString 27 //0x1B
61
#define kASN1TagUniversalString 28 //0x1C
62
#define kASN1TagCHARACTER 29 //0x1D
63
#define kASN1TagBMPString 30 //0x1E
64
#define kASN1TagPrivate (char)0xff
65
66
typedef struct{
67
byte tagNumber : 5;
68
byte isConstructed : 1;
69
byte tagClass : 2;
70
}t_asn1Tag;
71
72
typedef struct{
73
byte len : 7;
74
byte isLong : 1;
75
}t_asn1Length;
76
77
typedef struct{
78
size_t dataLen;
79
size_t sizeBytes;
80
} t_asn1ElemLen;
81
82
typedef struct{
83
byte num : 7;
84
byte more : 1;
85
}t_asn1PrivateTag;
86
87
88
#ifndef __cplusplus
89
typedef enum{
90
false,
91
true
92
}bool;
93
#endif
94
95
//asn1
96
t_asn1ElemLen asn1Len(const char buf[4]);
97
char *ans1GetString(char *buf, char **outString, size_t *strlen);
98
int asn1ElementsInObject(const char *buf);
99
char *asn1ElementAtIndex(const char *buf, int index);
100
101
102
char *getValueForTagInSet(char *set, uint32_t tag);
103
104
105
//img4
106
void printIM4P(char *buf);
107
void printIM4R(char *buf);
108
void printIM4M(char *buf, bool printAll);
109
void printMANB(char *buf, bool printAll);
110
111
int sequenceHasName(const char *buf, char *name);
112
int getSequenceName(const char *buf,char**name, size_t *nameLen);
113
size_t asn1GetPrivateTagnum(t_asn1Tag *tag, size_t *sizebytes);
114
int extractFileFromIM4P(char *buf, const char *dstFilename);
115
void printElemsInIMG4(char *buf, bool printAll, bool im4pOnly);
116
117
char *getElementFromIMG4(char *buf, char* element);
118
int extractElementFromIMG4(char *buf, char* element, const char *dstFilename);
119
char *makeIMG4(char *im4p, char *im4m, char *im4r, size_t *size);
120
121
char *getBNCHFromIM4M(const char* im4m, size_t *nonceSize);
122
char *getIM4PFromIMG4(char *buf);
123
char *getIM4MFromIMG4(char *buf);
124
125
int replaceNameInIM4P(char *buf, const char *newName);
126
int verifyIM4MSignature(const char *buf);
127
//int verifyIMG4(char *buf, plist_t buildmanifest);
128
129
//plist_t getBuildIdentityForIM4M(const char *buf, const plist_t buildmanifest);
130
//void printGeneralBuildIdentityInformation(plist_t buildidentity);
131
132
char* extractPayloadFromIM4P(const char* buf, const char** compname, size_t *len);
133
134
#ifdef __cplusplus
135
}
136
#endif
137
138
#endif /* img4_h */
139
140