summaryrefslogtreecommitdiff
path: root/view/sharedcache/api/sharedcachecore.h
blob: 1c382e487d3a58dea60f6314d6960438a930600f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#pragma once


#ifdef __cplusplus
extern "C"
{
#endif

#ifdef __GNUC__
	#ifdef SHAREDCACHE_LIBRARY
		#define SHAREDCACHE_FFI_API __attribute__((visibility("default")))
	#else  // SHAREDCACHE_LIBRARY
		#define SHAREDCACHE_FFI_API
	#endif  // SHAREDCACHE_LIBRARY
#else       // __GNUC__
	#ifdef _MSC_VER
		#ifndef DEMO_VERSION
			#ifdef SHAREDCACHE_LIBRARY
				#define SHAREDCACHE_FFI_API __declspec(dllexport)
			#else  // SHAREDCACHE_LIBRARY
				#define SHAREDCACHE_FFI_API __declspec(dllimport)
			#endif  // SHAREDCACHE_LIBRARY
		#else
			#define SHAREDCACHE_FFI_API
		#endif
	#else  // _MSC_VER
		#define SHAREDCACHE_FFI_API
	#endif  // _MSC_VER
#endif      // __GNUC__C

#define CORE_ALLOCATED_STRUCT(T)

#define CORE_ALLOCATED_CLASS(T) \
	public: \
		CORE_ALLOCATED_STRUCT(T) \
	private:

#define DECLARE_SHAREDCACHE_API_OBJECT_INTERNAL(handle, cls, ns) \
	namespace ns { class cls; } struct handle { ns::cls* object; }

#define DECLARE_SHAREDCACHE_API_OBJECT(handle, cls) DECLARE_SHAREDCACHE_API_OBJECT_INTERNAL(handle, cls, SharedCacheCore)

#define IMPLEMENT_SHAREDCACHE_API_OBJECT(handle) \
		CORE_ALLOCATED_CLASS(handle) \
	private: \
		handle m_apiObject; \
	public: \
		typedef handle* APIHandle; \
		handle* GetAPIObject() { return &m_apiObject; } \
	private:
#define INIT_SHAREDCACHE_API_OBJECT() \
	m_apiObject.object = this;

	typedef enum BNDSCViewState {
		Unloaded,
		Loaded,
		LoadedWithImages,
	} BNDSCViewState;

	typedef enum BNDSCViewLoadProgress {
		LoadProgressNotStarted,
		LoadProgressLoadingCaches,
		LoadProgressLoadingImages,
		LoadProgressFinished,
	} BNDSCViewLoadProgress;

	typedef struct BNBinaryView BNBinaryView;
	typedef struct BNSharedCache BNSharedCache;

	typedef struct BNDSCImageMemoryMapping {
		char* filePath;
		char* name;
		uint64_t vmAddress;
		uint64_t size;
		bool loaded;
		uint64_t rawViewOffset;
	} BNDSCImageMemoryMapping;

	typedef struct BNDSCImage {
		char* name;
		uint64_t headerAddress;
		BNDSCImageMemoryMapping* mappings;
		size_t mappingCount;
	} BNDSCImage;

	typedef struct BNDSCMappedMemoryRegion {
		uint64_t vmAddress;
		uint64_t size;
		char* name;
	} BNDSCMappedMemoryRegion;

	typedef struct BNDSCBackingCacheMapping {
		uint64_t vmAddress;
		uint64_t size;
		uint64_t fileOffset;
	} BNDSCBackingCacheMapping;

	typedef struct BNDSCBackingCache {
		char* path;
		bool isPrimary;
		BNDSCBackingCacheMapping* mappings;
		size_t mappingCount;
	} BNDSCBackingCache;

	typedef struct BNDSCMemoryUsageInfo {
		uint64_t sharedCacheRefs;
		uint64_t mmapRefs;
	} BNDSCMemoryUsageInfo;

	typedef struct BNDSCSymbolRep {
		uint64_t address;
		char* name;
		char* image;
	} BNDSCSymbolRep;

	SHAREDCACHE_FFI_API BNSharedCache* BNGetSharedCache(BNBinaryView* data);

	SHAREDCACHE_FFI_API BNSharedCache* BNNewSharedCacheReference(BNSharedCache* cache);
	SHAREDCACHE_FFI_API void BNFreeSharedCacheReference(BNSharedCache* cache);

	SHAREDCACHE_FFI_API char** BNDSCViewGetInstallNames(BNSharedCache* cache, size_t* count);
	SHAREDCACHE_FFI_API uint64_t BNDSCViewLoadedImageCount(BNSharedCache* cache);

	SHAREDCACHE_FFI_API bool BNDSCViewLoadImageWithInstallName(BNSharedCache* cache, char* name);
	SHAREDCACHE_FFI_API bool BNDSCViewLoadSectionAtAddress(BNSharedCache* cache, uint64_t name);
	SHAREDCACHE_FFI_API bool BNDSCViewLoadImageContainingAddress(BNSharedCache* cache, uint64_t address);

	SHAREDCACHE_FFI_API char* BNDSCViewGetNameForAddress(BNSharedCache* cache, uint64_t address);
	SHAREDCACHE_FFI_API char* BNDSCViewGetImageNameForAddress(BNSharedCache* cache, uint64_t address);

	SHAREDCACHE_FFI_API BNDSCViewState BNDSCViewGetState(BNSharedCache* cache);
	SHAREDCACHE_FFI_API BNDSCViewLoadProgress BNDSCViewGetLoadProgress(uint64_t sessionID);
	SHAREDCACHE_FFI_API uint64_t BNDSCViewFastGetBackingCacheCount(BNBinaryView* view);

	SHAREDCACHE_FFI_API BNDSCSymbolRep* BNDSCViewLoadAllSymbolsAndWait(BNSharedCache* cache, size_t* count);
	SHAREDCACHE_FFI_API void BNDSCViewFreeSymbols(BNDSCSymbolRep* symbols, size_t count);

	SHAREDCACHE_FFI_API BNDSCMappedMemoryRegion* BNDSCViewGetLoadedRegions(BNSharedCache* cache, size_t* count);
	SHAREDCACHE_FFI_API void BNDSCViewFreeLoadedRegions(BNDSCMappedMemoryRegion* images, size_t count);

	SHAREDCACHE_FFI_API BNDSCImage* BNDSCViewGetAllImages(BNSharedCache* cache, size_t* count);
	SHAREDCACHE_FFI_API void BNDSCViewFreeAllImages(BNDSCImage* images, size_t count);

	SHAREDCACHE_FFI_API BNDSCBackingCache* BNDSCViewGetBackingCaches(BNSharedCache* cache, size_t* count);
	SHAREDCACHE_FFI_API void BNDSCViewFreeBackingCaches(BNDSCBackingCache* caches, size_t count);

	SHAREDCACHE_FFI_API void BNDSCFindSymbolAtAddressAndApplyToAddress(BNSharedCache* cache, uint64_t symbolLocation, uint64_t targetLocation, bool triggerReanalysis);

	SHAREDCACHE_FFI_API char* BNDSCViewGetImageHeaderForAddress(BNSharedCache* cache, uint64_t address);
	SHAREDCACHE_FFI_API char* BNDSCViewGetImageHeaderForName(BNSharedCache* cache, char* name);

	[[maybe_unused]] SHAREDCACHE_FFI_API BNDSCMemoryUsageInfo BNDSCViewGetMemoryUsageInfo();

#ifdef __cplusplus
}
#endif