| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "asar.h" |
| 2 |
|
|
#include "crc32.h" |
| 3 |
|
|
#include "virtualfile.h" |
| 4 |
|
|
#include "platform/file-helpers.h" |
| 5 |
|
|
#include "interface-shared.h" |
| 6 |
|
|
#include "assembleblock.h" |
| 7 |
|
|
#include "asar_math.h" |
| 8 |
|
|
#include "platform/thread-helpers.h" |
| 9 |
|
|
#include <algorithm> |
| 10 |
|
|
|
| 11 |
|
|
#if defined(CPPCLI) |
| 12 |
|
|
#define EXPORT extern "C" |
| 13 |
|
|
#elif defined(_WIN32) |
| 14 |
|
|
#ifdef ASAR_SHARED |
| 15 |
|
|
#define EXPORT extern "C" __declspec(dllexport) |
| 16 |
|
|
#elif defined(ASAR_STATIC) |
| 17 |
|
|
#define EXPORT extern "C" |
| 18 |
|
|
#endif |
| 19 |
|
|
#else |
| 20 |
|
|
#define EXPORT extern "C" __attribute__ ((visibility ("default"))) |
| 21 |
|
|
#endif |
| 22 |
|
|
|
| 23 |
|
|
static autoarray<const char *> prints; |
| 24 |
|
|
static string symbolsfile; |
| 25 |
|
|
static int numprint; |
| 26 |
|
|
static uint32_t romCrc; |
| 27 |
|
|
|
| 28 |
|
|
#define APIVERSION 400 |
| 29 |
|
|
|
| 30 |
|
|
// note: somewhat fragile, assumes that every patchparams struct inherits from exactly the previous one |
| 31 |
|
|
/* $EXPORTSTRUCT_PP$ |
| 32 |
|
|
*/ |
| 33 |
|
|
struct patchparams_base { |
| 34 |
|
|
// The size of this struct. Set to (int)sizeof(patchparams). |
| 35 |
|
|
int structsize; |
| 36 |
|
|
}; |
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
/* $EXPORTSTRUCT$ |
| 40 |
|
|
*/ |
| 41 |
|
|
struct stackentry { |
| 42 |
|
|
const char * fullpath; |
| 43 |
|
|
const char * prettypath; |
| 44 |
|
|
int lineno; |
| 45 |
|
|
const char * details; |
| 46 |
|
|
}; |
| 47 |
|
|
|
| 48 |
|
|
/* $EXPORTSTRUCT$ |
| 49 |
|
|
*/ |
| 50 |
|
|
struct errordata { |
| 51 |
|
|
const char * fullerrdata; |
| 52 |
|
|
const char * rawerrdata; |
| 53 |
|
|
const char * block; |
| 54 |
|
|
const char * filename; |
| 55 |
|
|
int line; |
| 56 |
|
|
const struct stackentry * callstack; |
| 57 |
|
|
int callstacksize; |
| 58 |
|
|
const char * errname; |
| 59 |
|
|
}; |
| 60 |
|
|
static autoarray<errordata> errors; |
| 61 |
|
|
static int numerror; |
| 62 |
|
|
|
| 63 |
|
|
static autoarray<errordata> warnings; |
| 64 |
|
|
static int numwarn; |
| 65 |
|
|
|
| 66 |
|
|
/* $EXPORTSTRUCT$ |
| 67 |
|
|
*/ |
| 68 |
|
|
struct labeldata { |
| 69 |
|
|
const char * name; |
| 70 |
|
|
int location; |
| 71 |
|
|
}; |
| 72 |
|
|
|
| 73 |
|
|
/* $EXPORTSTRUCT$ |
| 74 |
|
|
*/ |
| 75 |
|
|
struct definedata { |
| 76 |
|
|
const char * name; |
| 77 |
|
|
const char * contents; |
| 78 |
|
|
}; |
| 79 |
|
|
|
| 80 |
|
|
/* $EXPORTSTRUCT$ |
| 81 |
|
|
*/ |
| 82 |
|
|
struct warnsetting { |
| 83 |
|
|
const char * warnid; |
| 84 |
|
|
bool enabled; |
| 85 |
|
|
}; |
| 86 |
|
|
|
| 87 |
|
|
/* $EXPORTSTRUCT$ |
| 88 |
|
|
*/ |
| 89 |
|
|
struct memoryfile { |
| 90 |
|
|
const char* path; |
| 91 |
|
|
const void* buffer; |
| 92 |
|
|
size_t length; |
| 93 |
|
|
}; |
| 94 |
|
|
|
| 95 |
|
100 |
void print(const char * str) |
| 96 |
|
|
{ |
| 97 |
|
100 |
prints[numprint++]= duplicate_string(str); |
| 98 |
|
100 |
} |
| 99 |
|
|
|
| 100 |
|
268 |
static void fillerror(errordata& myerr, const char* errname, const char * type, const char * str, bool show_block) |
| 101 |
|
|
{ |
| 102 |
1/2
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
|
268 |
const char* current_filename = get_current_file_name(); |
| 103 |
2/2
✓ Branch 0 taken 263 times.
✓ Branch 1 taken 5 times.
|
268 |
if(current_filename) myerr.filename= duplicate_string(current_filename); |
| 104 |
|
5 |
else myerr.filename = duplicate_string(""); |
| 105 |
1/2
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
|
268 |
myerr.line=get_current_line(); |
| 106 |
1/2
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
|
268 |
const char* current_block = get_current_block(); |
| 107 |
2/2
✓ Branch 0 taken 257 times.
✓ Branch 1 taken 11 times.
|
268 |
if (current_block) myerr.block= duplicate_string(current_block); |
| 108 |
|
11 |
else myerr.block= duplicate_string(""); |
| 109 |
|
268 |
myerr.rawerrdata= duplicate_string(str); |
| 110 |
|
268 |
string location; |
| 111 |
|
268 |
string details; |
| 112 |
1/2
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
|
268 |
get_current_line_details(&location, &details); |
| 113 |
8/16
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 268 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 132 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 268 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 136 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 136 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 136 times.
✗ Branch 15 not taken.
|
268 |
myerr.fullerrdata= duplicate_string(location+type+str+details+get_callstack()); |
| 114 |
|
268 |
myerr.errname = duplicate_string(errname); |
| 115 |
|
|
|
| 116 |
|
268 |
autoarray<printable_callstack_entry> printable_stack; |
| 117 |
1/2
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
|
268 |
get_full_printable_callstack(&printable_stack, 0, false); |
| 118 |
|
|
|
| 119 |
|
268 |
myerr.callstacksize = printable_stack.count; |
| 120 |
|
268 |
myerr.callstack = static_cast<stackentry*>(malloc(sizeof(stackentry) * myerr.callstacksize)); |
| 121 |
|
|
|
| 122 |
4/4
✓ Branch 0 taken 5023 times.
✓ Branch 1 taken 132 times.
✓ Branch 2 taken 5023 times.
✓ Branch 3 taken 136 times.
|
10314 |
for (int i = 0; i < myerr.callstacksize; ++i) |
| 123 |
|
|
{ |
| 124 |
|
10046 |
stackentry& entry = const_cast<stackentry&>(myerr.callstack[i]); |
| 125 |
|
|
|
| 126 |
1/2
✓ Branch 0 taken 10046 times.
✗ Branch 1 not taken.
|
10046 |
entry.fullpath = duplicate_string(printable_stack[i].fullpath); |
| 127 |
1/2
✓ Branch 0 taken 10046 times.
✗ Branch 1 not taken.
|
10046 |
entry.prettypath = duplicate_string(printable_stack[i].prettypath); |
| 128 |
1/2
✓ Branch 0 taken 10046 times.
✗ Branch 1 not taken.
|
10046 |
entry.lineno = printable_stack[i].lineno; |
| 129 |
1/2
✓ Branch 0 taken 10046 times.
✗ Branch 1 not taken.
|
10046 |
entry.details = duplicate_string(printable_stack[i].details); |
| 130 |
|
|
} |
| 131 |
|
404 |
} |
| 132 |
|
|
|
| 133 |
|
|
static bool ismath=false; |
| 134 |
|
|
static string matherror; |
| 135 |
|
|
|
| 136 |
|
473 |
void error_interface(const char* errid, int whichpass, const char * e_) |
| 137 |
|
|
{ |
| 138 |
|
473 |
errored = true; |
| 139 |
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 473 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 240 times.
|
473 |
if (ismath) matherror = e_; |
| 140 |
2/2
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 246 times.
|
472 |
else if (pass == whichpass) { |
| 141 |
|
|
// don't show current block if the error came from an error command |
| 142 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
|
226 |
bool show_block = (strcmp(errid, "error_command") != 0); |
| 143 |
7/14
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 226 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 226 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 226 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 112 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 114 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 114 times.
✗ Branch 13 not taken.
|
226 |
fillerror(errors[numerror++], errid, STR "error: (" + errid + "): ", e_, show_block); |
| 144 |
|
|
} |
| 145 |
|
|
else {}//ignore anything else |
| 146 |
|
473 |
} |
| 147 |
|
|
|
| 148 |
|
42 |
void warn(int errid, const char * str) |
| 149 |
|
|
{ |
| 150 |
|
|
// don't show current block if the warning came from a warn command |
| 151 |
|
42 |
bool show_block = (errid != warn_id_warn_command); |
| 152 |
13/20
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 22 times.
✓ Branch 6 taken 20 times.
✓ Branch 7 taken 22 times.
✓ Branch 8 taken 20 times.
✓ Branch 9 taken 22 times.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 20 times.
✓ Branch 13 taken 22 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 22 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 22 times.
✗ Branch 19 not taken.
|
42 |
fillerror(warnings[numwarn++], get_warning_name((asar_warning_id)errid), STR "warning: (" + get_warning_name((asar_warning_id)errid) + "): ", str, show_block); |
| 153 |
|
42 |
} |
| 154 |
|
|
|
| 155 |
|
|
static autoarray<labeldata> ldata; |
| 156 |
|
|
static int labelsinldata = 0; |
| 157 |
|
|
static autoarray<definedata> ddata; |
| 158 |
|
|
static int definesinddata=0; |
| 159 |
|
|
|
| 160 |
|
289 |
static void resetdllstuff() |
| 161 |
|
|
{ |
| 162 |
|
|
#define free_and_null(x) free((void*)x); x = nullptr |
| 163 |
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 289 times.
|
389 |
for (int i=0;i<numprint;i++) |
| 164 |
|
|
{ |
| 165 |
|
100 |
free_and_null(prints[i]); |
| 166 |
|
|
} |
| 167 |
|
289 |
prints.reset(); |
| 168 |
|
289 |
numprint=0; |
| 169 |
|
|
|
| 170 |
2/2
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 289 times.
|
515 |
for (int i=0;i<numerror;i++) |
| 171 |
|
|
{ |
| 172 |
|
226 |
free_and_null(errors[i].filename); |
| 173 |
|
226 |
free_and_null(errors[i].rawerrdata); |
| 174 |
|
226 |
free_and_null(errors[i].fullerrdata); |
| 175 |
|
226 |
free_and_null(errors[i].block); |
| 176 |
|
226 |
free_and_null(errors[i].errname); |
| 177 |
|
|
|
| 178 |
4/4
✓ Branch 0 taken 5023 times.
✓ Branch 1 taken 112 times.
✓ Branch 2 taken 5023 times.
✓ Branch 3 taken 114 times.
|
10272 |
for (int j=0;j<errors[i].callstacksize;++j) |
| 179 |
|
|
{ |
| 180 |
|
10046 |
stackentry& entry = const_cast<stackentry&>(errors[i].callstack[j]); |
| 181 |
|
10046 |
free_and_null(entry.fullpath); |
| 182 |
|
10046 |
free_and_null(entry.prettypath); |
| 183 |
|
10046 |
free_and_null(entry.details); |
| 184 |
|
|
} |
| 185 |
|
226 |
free_and_null(errors[i].callstack); |
| 186 |
|
|
} |
| 187 |
|
289 |
errors.reset(); |
| 188 |
|
289 |
numerror=0; |
| 189 |
|
|
|
| 190 |
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 289 times.
|
331 |
for (int i=0;i<numwarn;i++) |
| 191 |
|
|
{ |
| 192 |
|
42 |
free_and_null(warnings[i].filename); |
| 193 |
|
42 |
free_and_null(warnings[i].rawerrdata); |
| 194 |
|
42 |
free_and_null(warnings[i].fullerrdata); |
| 195 |
|
42 |
free_and_null(warnings[i].block); |
| 196 |
|
42 |
free_and_null(warnings[i].errname); |
| 197 |
|
|
|
| 198 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
|
42 |
for (int j=0;j<warnings[i].callstacksize;++j) |
| 199 |
|
|
{ |
| 200 |
|
✗ |
stackentry& entry = const_cast<stackentry&>(warnings[i].callstack[j]); |
| 201 |
|
✗ |
free_and_null(entry.fullpath); |
| 202 |
|
✗ |
free_and_null(entry.prettypath); |
| 203 |
|
✗ |
free_and_null(entry.details); |
| 204 |
|
|
} |
| 205 |
|
42 |
free_and_null(warnings[i].callstack); |
| 206 |
|
|
} |
| 207 |
|
289 |
warnings.reset(); |
| 208 |
|
289 |
numwarn=0; |
| 209 |
|
|
|
| 210 |
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 289 times.
|
306 |
for (int i=0;i<definesinddata;i++) |
| 211 |
|
|
{ |
| 212 |
|
17 |
free_and_null(ddata[i].name); |
| 213 |
|
17 |
free_and_null(ddata[i].contents); |
| 214 |
|
|
} |
| 215 |
|
289 |
ddata.reset(); |
| 216 |
|
289 |
definesinddata=0; |
| 217 |
|
|
|
| 218 |
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 289 times.
|
294 |
for (int i=0;i<labelsinldata;i++) |
| 219 |
|
5 |
free((void*)ldata[i].name); |
| 220 |
|
289 |
ldata.reset(); |
| 221 |
|
289 |
labelsinldata=0; |
| 222 |
|
|
#undef free_and_null |
| 223 |
|
|
|
| 224 |
|
289 |
romCrc = 0; |
| 225 |
|
289 |
clidefines.reset(); |
| 226 |
|
289 |
reset_warnings_to_default(); |
| 227 |
|
|
|
| 228 |
|
289 |
reseteverything(); |
| 229 |
|
289 |
} |
| 230 |
|
|
|
| 231 |
|
|
#define maxromsize (16*1024*1024) |
| 232 |
|
|
|
| 233 |
|
|
static bool expectsNewAPI = false; |
| 234 |
|
|
|
| 235 |
|
|
/* $EXPORTSTRUCT_PP$ |
| 236 |
|
|
*/ |
| 237 |
|
|
struct patchparams_v200 : public patchparams_base |
| 238 |
|
|
{ |
| 239 |
|
|
// Same parameters as asar_patch() |
| 240 |
|
|
const char * patchloc; |
| 241 |
|
|
char * romdata; |
| 242 |
|
|
int buflen; |
| 243 |
|
|
int * romlen; |
| 244 |
|
|
|
| 245 |
|
|
// Include paths to use when searching files. |
| 246 |
|
|
const char** includepaths; |
| 247 |
|
|
int numincludepaths; |
| 248 |
|
|
|
| 249 |
|
|
// A list of additional defines to make available to the patch. |
| 250 |
|
|
const struct definedata* additional_defines; |
| 251 |
|
|
int additional_define_count; |
| 252 |
|
|
|
| 253 |
|
|
// Path to a text file to parse standard include search paths from. |
| 254 |
|
|
// Set to NULL to not use any standard includes search paths. |
| 255 |
|
|
const char* stdincludesfile; |
| 256 |
|
|
|
| 257 |
|
|
// Path to a text file to parse standard defines from. |
| 258 |
|
|
// Set to NULL to not use any standard defines. |
| 259 |
|
|
const char* stddefinesfile; |
| 260 |
|
|
|
| 261 |
|
|
// A list of warnings to enable or disable. |
| 262 |
|
|
// Specify warnings in the format "WXXXX" where XXXX = warning ID. |
| 263 |
|
|
const struct warnsetting * warning_settings; |
| 264 |
|
|
int warning_setting_count; |
| 265 |
|
|
|
| 266 |
|
|
// List of memory files to create on the virtual filesystem. |
| 267 |
|
|
const struct memoryfile * memory_files; |
| 268 |
|
|
int memory_file_count; |
| 269 |
|
|
|
| 270 |
|
|
// Set override_checksum_gen to true and generate_checksum to true/false |
| 271 |
|
|
// to force generating/not generating a checksum. |
| 272 |
|
|
bool override_checksum_gen; |
| 273 |
|
|
bool generate_checksum; |
| 274 |
|
|
|
| 275 |
|
|
// Set this to true for generated error and warning texts to always |
| 276 |
|
|
// contain their full call stack. |
| 277 |
|
|
bool full_call_stack; |
| 278 |
|
|
}; |
| 279 |
|
|
|
| 280 |
|
|
/* $EXPORTSTRUCT_PP$ |
| 281 |
|
|
*/ |
| 282 |
|
|
struct patchparams : public patchparams_v200 |
| 283 |
|
|
{ |
| 284 |
|
|
|
| 285 |
|
|
}; |
| 286 |
|
|
|
| 287 |
|
286 |
static void asar_patch_begin(char * romdata_, int buflen, int * romlen_) |
| 288 |
|
|
{ |
| 289 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 286 times.
|
286 |
if (buflen != maxromsize) |
| 290 |
|
|
{ |
| 291 |
|
✗ |
romdata_r = (unsigned char*)malloc(maxromsize); |
| 292 |
|
✗ |
memcpy(const_cast<unsigned char*>(romdata_r)/*we just allocated this, it's safe to violate its const*/, romdata_, (size_t)*romlen_); |
| 293 |
|
|
} |
| 294 |
|
286 |
else romdata_r = (unsigned char*)romdata_; |
| 295 |
|
286 |
romdata = (unsigned char*)malloc(maxromsize); |
| 296 |
|
|
// RPG Hacker: Without this memset, freespace commands can (and probably will) fail. |
| 297 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 157 times.
|
286 |
memset((void*)romdata, 0, maxromsize); |
| 298 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 157 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 157 times.
|
286 |
memcpy(const_cast<unsigned char*>(romdata), romdata_, (size_t)*romlen_); |
| 299 |
|
286 |
resetdllstuff(); |
| 300 |
|
286 |
romlen = *romlen_; |
| 301 |
|
286 |
romlen_r = *romlen_; |
| 302 |
|
286 |
} |
| 303 |
|
|
|
| 304 |
|
286 |
static void asar_patch_main(const char * patchloc) |
| 305 |
|
|
{ |
| 306 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 285 times.
|
286 |
if (!path_is_absolute(patchloc)) throw_warning(pass, warn_relative_path_used, "patch file"); |
| 307 |
|
|
|
| 308 |
|
|
try |
| 309 |
|
|
{ |
| 310 |
2/2
✓ Branch 0 taken 838 times.
✓ Branch 1 taken 276 times.
|
1114 |
for (pass = 0;pass < 3;pass++) |
| 311 |
|
|
{ |
| 312 |
1/2
✓ Branch 0 taken 838 times.
✗ Branch 1 not taken.
|
838 |
initstuff(); |
| 313 |
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 10 times.
|
838 |
assemblefile(patchloc); |
| 314 |
|
|
// RPG Hacker: Necessary, because finishpass() can throws warning and errors. |
| 315 |
2/3
✓ Branch 0 taken 372 times.
✓ Branch 1 taken 456 times.
✗ Branch 2 not taken.
|
828 |
string asmpath = filesystem->create_absolute_path(nullptr, patchloc); |
| 316 |
2/3
✓ Branch 0 taken 372 times.
✓ Branch 1 taken 456 times.
✗ Branch 2 not taken.
|
828 |
callstack_push cs_push(callstack_entry_type::FILE, asmpath); |
| 317 |
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
|
828 |
finishpass(); |
| 318 |
|
828 |
} |
| 319 |
|
|
} |
| 320 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 |
catch (errfatal&) {} |
| 321 |
|
286 |
} |
| 322 |
|
|
|
| 323 |
|
286 |
static bool asar_patch_end(char * romdata_, int buflen, int * romlen_) |
| 324 |
|
|
{ |
| 325 |
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 286 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 133 times.
|
286 |
if (checksum_fix_enabled) fixchecksum(); |
| 326 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 286 times.
|
286 |
if (romdata_ != (const char*)romdata_r) free(const_cast<unsigned char*>(romdata_r)); |
| 327 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 286 times.
|
286 |
if (buflen < romlen) throw_err_null(pass, err_buffer_too_small); |
| 328 |
4/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 249 times.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 119 times.
|
286 |
if (errored) |
| 329 |
|
|
{ |
| 330 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
|
75 |
if (numerror==0) |
| 331 |
|
✗ |
throw_err_null(pass, err_internal_error, "phantom error"); |
| 332 |
|
75 |
free(const_cast<unsigned char*>(romdata)); |
| 333 |
|
75 |
return false; |
| 334 |
|
|
} |
| 335 |
2/3
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
|
211 |
if (*romlen_ != buflen) |
| 336 |
|
|
{ |
| 337 |
|
211 |
*romlen_ = romlen; |
| 338 |
|
|
} |
| 339 |
|
211 |
romCrc = crc32((const uint8_t*)romdata, (size_t)romlen); |
| 340 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 119 times.
|
211 |
memcpy(romdata_, romdata, (size_t)romlen); |
| 341 |
|
211 |
free(const_cast<unsigned char*>(romdata)); |
| 342 |
|
211 |
return true; |
| 343 |
|
|
} |
| 344 |
|
|
|
| 345 |
|
|
#if defined(__clang__) |
| 346 |
|
|
# pragma clang diagnostic push |
| 347 |
|
|
# pragma clang diagnostic ignored "-Wmissing-prototypes" |
| 348 |
|
|
#endif |
| 349 |
|
|
|
| 350 |
|
|
// this and asar_close are hardcoded in each api |
| 351 |
|
3 |
EXPORT bool asar_init() |
| 352 |
|
|
{ |
| 353 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
3 |
if (!expectsNewAPI) return false; |
| 354 |
|
3 |
return true; |
| 355 |
|
|
} |
| 356 |
|
|
|
| 357 |
|
|
/* $EXPORT$ |
| 358 |
|
|
* Returns the version, in the format major*10000+minor*100+bugfix*1. This |
| 359 |
|
|
* means that 1.2.34 would be returned as 10234. |
| 360 |
|
|
*/ |
| 361 |
|
1 |
EXPORT int asar_version() |
| 362 |
|
|
{ |
| 363 |
|
1 |
return get_version_int(); |
| 364 |
|
|
} |
| 365 |
|
|
|
| 366 |
|
|
/* $EXPORT$ |
| 367 |
|
|
* Returns the API version, format major*100+minor. Minor is incremented on |
| 368 |
|
|
* backwards compatible changes; major is incremented on incompatible changes. |
| 369 |
|
|
* Does not have any correlation with the Asar version. |
| 370 |
|
|
* |
| 371 |
|
|
* It's not very useful directly, since asar_init() verifies this automatically. |
| 372 |
|
|
* Calling this one also sets a flag that makes asar_init not instantly return |
| 373 |
|
|
* false; this is so programs expecting an older API won't do anything unexpected. |
| 374 |
|
|
*/ |
| 375 |
|
5 |
EXPORT int asar_apiversion() |
| 376 |
|
|
{ |
| 377 |
|
5 |
expectsNewAPI=true; |
| 378 |
|
5 |
return APIVERSION; |
| 379 |
|
|
} |
| 380 |
|
|
|
| 381 |
|
|
/* $EXPORT$ |
| 382 |
|
|
* Clears out all errors, warnings and printed statements, and clears the file |
| 383 |
|
|
* cache. Not really useful, since asar_patch() already does this. |
| 384 |
|
|
*/ |
| 385 |
|
✗ |
EXPORT bool asar_reset() |
| 386 |
|
|
{ |
| 387 |
|
✗ |
resetdllstuff(); |
| 388 |
|
✗ |
pass=0; |
| 389 |
|
✗ |
return true; |
| 390 |
|
|
} |
| 391 |
|
|
|
| 392 |
|
3 |
EXPORT void asar_close() |
| 393 |
|
|
{ |
| 394 |
|
3 |
resetdllstuff(); |
| 395 |
|
3 |
} |
| 396 |
|
|
|
| 397 |
|
|
/* $EXPORT$ |
| 398 |
|
|
* Applies a patch. The first argument is a filename (so Asar knows where to |
| 399 |
|
|
* look for incsrc'd stuff); however, the ROM is in memory. |
| 400 |
|
|
* This function assumes there are no headers anywhere, neither in romdata nor |
| 401 |
|
|
* the sizes. romlen may be altered by this function; if this is undesirable, |
| 402 |
|
|
* set romlen equal to buflen. |
| 403 |
|
|
* The return value is whether any errors appeared (false=errors, call |
| 404 |
|
|
* asar_geterrors for details). If there is an error, romdata and romlen will |
| 405 |
|
|
* be left unchanged. |
| 406 |
|
|
* See the documentation of struct patchparams for more information. |
| 407 |
|
|
*/ |
| 408 |
|
286 |
EXPORT bool asar_patch(const struct patchparams_base *params) |
| 409 |
|
|
{ |
| 410 |
|
286 |
auto execute_patch = [&]() { |
| 411 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 157 times.
|
286 |
if (params == nullptr) |
| 412 |
|
|
{ |
| 413 |
|
✗ |
throw_err_null(pass, err_params_null); |
| 414 |
|
|
} |
| 415 |
|
|
|
| 416 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 157 times.
|
286 |
if (params->structsize != sizeof(patchparams_v200)) |
| 417 |
|
|
{ |
| 418 |
|
✗ |
throw_err_null(pass, err_params_invalid_size); |
| 419 |
|
|
} |
| 420 |
|
|
|
| 421 |
|
157 |
patchparams paramscurrent; |
| 422 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 157 times.
|
286 |
memset(¶mscurrent, 0, sizeof(paramscurrent)); |
| 423 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 157 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 157 times.
|
286 |
memcpy(¶mscurrent, params, (size_t)params->structsize); |
| 424 |
|
|
|
| 425 |
|
|
|
| 426 |
1/2
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
|
286 |
asar_patch_begin(paramscurrent.romdata, paramscurrent.buflen, paramscurrent.romlen); |
| 427 |
|
|
|
| 428 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 157 times.
|
286 |
simple_callstacks = !paramscurrent.full_call_stack; |
| 429 |
|
|
|
| 430 |
|
286 |
autoarray<string> includepaths; |
| 431 |
|
286 |
autoarray<const char*> includepath_cstrs; |
| 432 |
|
|
|
| 433 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 286 times.
|
287 |
for (int i = 0; i < paramscurrent.numincludepaths; ++i) |
| 434 |
|
|
{ |
| 435 |
2/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
1 |
if (!path_is_absolute(paramscurrent.includepaths[i])) throw_warning(pass, warn_relative_path_used, "include search"); |
| 436 |
2/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 |
string& newpath = includepaths.append(paramscurrent.includepaths[i]); |
| 437 |
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 |
includepath_cstrs.append((const char*)newpath); |
| 438 |
|
|
} |
| 439 |
|
|
|
| 440 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 285 times.
|
286 |
if (paramscurrent.stdincludesfile != nullptr) { |
| 441 |
2/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1 |
if (!path_is_absolute(paramscurrent.stdincludesfile)) throw_warning(pass, warn_relative_path_used, "std includes file"); |
| 442 |
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
string stdincludespath = paramscurrent.stdincludesfile; |
| 443 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
parse_std_includes(stdincludespath, includepaths); |
| 444 |
|
1 |
} |
| 445 |
|
|
|
| 446 |
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 286 times.
|
290 |
for (int i = 0; i < includepaths.count; ++i) |
| 447 |
|
|
{ |
| 448 |
2/7
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
|
4 |
includepath_cstrs.append((const char*)includepaths[i]); |
| 449 |
|
|
} |
| 450 |
|
|
|
| 451 |
|
286 |
size_t includepath_count = (size_t)includepath_cstrs.count; |
| 452 |
2/3
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 157 times.
✗ Branch 2 not taken.
|
286 |
virtual_filesystem new_filesystem; |
| 453 |
2/4
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 286 times.
✗ Branch 3 not taken.
|
286 |
new_filesystem.initialize(&includepath_cstrs[0], includepath_count); |
| 454 |
|
286 |
filesystem = &new_filesystem; |
| 455 |
|
|
|
| 456 |
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 286 times.
|
319 |
for(int i = 0; i < paramscurrent.memory_file_count; ++i) { |
| 457 |
|
33 |
memoryfile f = paramscurrent.memory_files[i]; |
| 458 |
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
|
33 |
filesystem->add_memory_file(f.path, f.buffer, f.length); |
| 459 |
|
|
} |
| 460 |
|
|
|
| 461 |
|
286 |
clidefines.reset(); |
| 462 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 286 times.
|
288 |
for (int i = 0; i < paramscurrent.additional_define_count; ++i) |
| 463 |
|
|
{ |
| 464 |
2/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
string name = (paramscurrent.additional_defines[i].name != nullptr ? paramscurrent.additional_defines[i].name : ""); |
| 465 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
strip_whitespace(name); |
| 466 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
name.strip_prefix('!'); // remove leading ! if present |
| 467 |
2/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2 |
if (!validatedefinename(name)) throw_err_null(pass, err_cmdl_define_invalid, "asar_patch_ex() additional defines", name.data()); |
| 468 |
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
|
2 |
if (clidefines.exists(name)) { |
| 469 |
|
✗ |
throw_err_null(pass, err_cmdl_define_override, "asar_patch_ex() additional define", name.data()); |
| 470 |
|
✗ |
return false; |
| 471 |
|
|
} |
| 472 |
2/7
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
2 |
string contents = (paramscurrent.additional_defines[i].contents != nullptr ? paramscurrent.additional_defines[i].contents : ""); |
| 473 |
2/7
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
2 |
clidefines.create(name) = contents; |
| 474 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
} |
| 475 |
|
|
|
| 476 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 285 times.
|
286 |
if (paramscurrent.stddefinesfile != nullptr) { |
| 477 |
2/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1 |
if (!path_is_absolute(paramscurrent.stddefinesfile)) throw_warning(pass, warn_relative_path_used, "std defines file"); |
| 478 |
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
string stddefinespath = paramscurrent.stddefinesfile; |
| 479 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
parse_std_defines(stddefinespath); |
| 480 |
|
1 |
} else { |
| 481 |
1/2
✓ Branch 0 taken 285 times.
✗ Branch 1 not taken.
|
285 |
parse_std_defines(nullptr); // needed to populate builtin defines |
| 482 |
|
|
} |
| 483 |
|
|
|
| 484 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 286 times.
|
288 |
for (int i = 0; i < paramscurrent.warning_setting_count; ++i) |
| 485 |
|
|
{ |
| 486 |
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 |
asar_warning_id warnid = parse_warning_id_from_string(paramscurrent.warning_settings[i].warnid); |
| 487 |
|
|
|
| 488 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
if (warnid != warning_id_end) |
| 489 |
|
|
{ |
| 490 |
2/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 |
set_warning_enabled(warnid, paramscurrent.warning_settings[i].enabled); |
| 491 |
|
|
} |
| 492 |
|
|
else |
| 493 |
|
|
{ |
| 494 |
|
✗ |
throw_warning(pass, warn_invalid_warning_id, paramscurrent.warning_settings[i].warnid, "asar_patch_ex() warning_settings"); |
| 495 |
|
|
} |
| 496 |
|
|
} |
| 497 |
|
|
|
| 498 |
4/4
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 157 times.
✓ Branch 2 taken 132 times.
✓ Branch 3 taken 25 times.
|
286 |
if(paramscurrent.override_checksum_gen) { |
| 499 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
|
261 |
checksum_fix_enabled = paramscurrent.generate_checksum; |
| 500 |
|
261 |
force_checksum_fix = true; |
| 501 |
|
|
} |
| 502 |
|
|
|
| 503 |
1/2
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
|
286 |
asar_patch_main(paramscurrent.patchloc); |
| 504 |
|
|
|
| 505 |
|
|
// RPG Hacker: Required before the destroy() below, |
| 506 |
|
|
// otherwise it will leak memory. |
| 507 |
1/2
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
|
286 |
closecachedfiles(); |
| 508 |
|
|
|
| 509 |
1/2
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
|
286 |
new_filesystem.destroy(); |
| 510 |
|
286 |
filesystem = nullptr; |
| 511 |
|
|
|
| 512 |
1/2
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
|
286 |
return asar_patch_end(paramscurrent.romdata, paramscurrent.buflen, paramscurrent.romlen); |
| 513 |
|
286 |
}; |
| 514 |
|
|
#if defined(RUN_VIA_FIBER) |
| 515 |
|
|
return run_as_fiber(execute_patch); |
| 516 |
|
|
#elif defined(RUN_VIA_THREAD) |
| 517 |
1/2
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
|
572 |
return run_as_thread(execute_patch); |
| 518 |
|
|
#else |
| 519 |
|
|
return execute_patch(); |
| 520 |
|
|
#endif |
| 521 |
|
|
} |
| 522 |
|
|
|
| 523 |
|
|
/* $EXPORT$ |
| 524 |
|
|
* Returns the maximum possible size of the output ROM from asar_patch(). |
| 525 |
|
|
* Giving this size to buflen guarantees you will not get any buffer too small |
| 526 |
|
|
* errors; however, it is safe to give smaller buffers if you don't expect any |
| 527 |
|
|
* ROMs larger than 4MB or something. |
| 528 |
|
|
*/ |
| 529 |
|
56 |
EXPORT int asar_maxromsize() |
| 530 |
|
|
{ |
| 531 |
|
56 |
return maxromsize; |
| 532 |
|
|
} |
| 533 |
|
|
|
| 534 |
|
|
/* $EXPORT$ |
| 535 |
|
|
* Get a list of all errors. |
| 536 |
|
|
* All pointers from these functions are valid only until the same function is |
| 537 |
|
|
* called again, or until asar_patch, asar_reset or asar_close is called, |
| 538 |
|
|
* whichever comes first. Copy the contents if you need it for a longer time. |
| 539 |
|
|
*/ |
| 540 |
|
276 |
EXPORT const struct errordata * asar_geterrors(int * count) |
| 541 |
|
|
{ |
| 542 |
|
276 |
*count=numerror; |
| 543 |
|
276 |
return errors; |
| 544 |
|
|
} |
| 545 |
|
|
|
| 546 |
|
|
/* $EXPORT$ |
| 547 |
|
|
* Get a list of all warnings. |
| 548 |
|
|
*/ |
| 549 |
|
276 |
EXPORT const struct errordata * asar_getwarnings(int * count) |
| 550 |
|
|
{ |
| 551 |
|
276 |
*count=numwarn; |
| 552 |
|
276 |
return warnings; |
| 553 |
|
|
} |
| 554 |
|
|
|
| 555 |
|
|
/* $EXPORT$ |
| 556 |
|
|
* Get a list of all printed data. |
| 557 |
|
|
*/ |
| 558 |
|
259 |
EXPORT const char * const * asar_getprints(int * count) |
| 559 |
|
|
{ |
| 560 |
|
259 |
*count=numprint; |
| 561 |
|
259 |
return prints; |
| 562 |
|
|
} |
| 563 |
|
|
|
| 564 |
|
|
/* $EXPORT$ |
| 565 |
|
|
* Get a list of all labels. |
| 566 |
|
|
*/ |
| 567 |
|
1 |
EXPORT const struct labeldata * asar_getalllabels(int * count) |
| 568 |
|
|
{ |
| 569 |
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 |
for (int i=0;i<labelsinldata;i++) free((void*)ldata[i].name); |
| 570 |
|
1 |
labelsinldata=0; |
| 571 |
|
1 |
labels.each([](const string& name, const snes_label& label_data) { |
| 572 |
|
5 |
labeldata label; |
| 573 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 |
label.name = strdup(name); |
| 574 |
|
5 |
label.location = (int)(label_data.pos & 0xFFFFFF); |
| 575 |
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 |
ldata[labelsinldata++] = label; |
| 576 |
|
5 |
}); |
| 577 |
|
1 |
*count=labelsinldata; |
| 578 |
|
1 |
std::sort<labeldata*>(ldata, ldata + labelsinldata, |
| 579 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
|
10 |
[](auto& l, auto& r) { return strcmp(l.name, r.name) < 0; }); |
| 580 |
|
1 |
return ldata; |
| 581 |
|
|
} |
| 582 |
|
|
|
| 583 |
|
|
/* $EXPORT$ |
| 584 |
|
|
* Get the ROM location of one label. -1 means "not found". |
| 585 |
|
|
*/ |
| 586 |
|
2 |
EXPORT int asar_getlabelval(const char * name) |
| 587 |
|
|
{ |
| 588 |
|
|
int i; |
| 589 |
|
|
try { |
| 590 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 |
i=(int)labelval(&name).pos; |
| 591 |
|
|
} |
| 592 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 |
catch(errfatal&) { return -1; } |
| 593 |
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 |
if (*name || i<0) return -1; |
| 594 |
|
1 |
else return i&0xFFFFFF; |
| 595 |
|
|
} |
| 596 |
|
|
|
| 597 |
|
|
/* $EXPORT$ |
| 598 |
|
|
* Get the value of a define. |
| 599 |
|
|
*/ |
| 600 |
|
2 |
EXPORT const char * asar_getdefine(const char * name) |
| 601 |
|
|
{ |
| 602 |
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
2 |
if (!defines.exists(name)) return ""; |
| 603 |
|
1 |
return defines.find(name); |
| 604 |
|
|
} |
| 605 |
|
|
|
| 606 |
|
|
/* $EXPORT$ |
| 607 |
|
|
* Parses all defines in the parameter. |
| 608 |
|
|
* If there were any errors, returns an empty string. |
| 609 |
|
|
*/ |
| 610 |
|
3 |
EXPORT const char * asar_resolvedefines(const char * data) |
| 611 |
|
|
{ |
| 612 |
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
3 |
static string out; |
| 613 |
|
3 |
out = ""; |
| 614 |
|
|
try |
| 615 |
|
|
{ |
| 616 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 |
resolvedefines(out, data); |
| 617 |
|
|
} |
| 618 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 |
catch(errfatal&){ |
| 619 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
out = ""; |
| 620 |
|
1 |
} |
| 621 |
|
3 |
return out; |
| 622 |
|
|
} |
| 623 |
|
|
|
| 624 |
|
|
/* $EXPORT$ |
| 625 |
|
|
* Gets the values and names of all defines. |
| 626 |
|
|
*/ |
| 627 |
|
3 |
EXPORT const struct definedata * asar_getalldefines(int * count) |
| 628 |
|
|
{ |
| 629 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 |
for (int i=0;i<definesinddata;i++) |
| 630 |
|
|
{ |
| 631 |
|
✗ |
free((void*)ddata[i].name); |
| 632 |
|
✗ |
free((void*)ddata[i].contents); |
| 633 |
|
|
} |
| 634 |
|
3 |
definesinddata=0; |
| 635 |
|
3 |
defines.each([](const string& name, string& value) { |
| 636 |
|
17 |
definedata define; |
| 637 |
|
17 |
define.name = duplicate_string(name); |
| 638 |
|
17 |
define.contents = duplicate_string(value); |
| 639 |
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 |
ddata[definesinddata++] = define; |
| 640 |
|
17 |
}); |
| 641 |
|
3 |
*count=definesinddata; |
| 642 |
|
3 |
std::sort<definedata*>(ddata, ddata + definesinddata, |
| 643 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 43 times.
|
43 |
[](auto& l, auto& r) { return strcmp(l.name, r.name) < 0; }); |
| 644 |
|
3 |
return ddata; |
| 645 |
|
|
} |
| 646 |
|
|
|
| 647 |
|
|
/* $EXPORT$ |
| 648 |
|
|
* Parses a string containing math. It automatically assumes global scope (no |
| 649 |
|
|
* namespaces), and has access to all functions and labels from the last call |
| 650 |
|
|
* to asar_patch. Remember to check error to see if it's successful (NULL) or |
| 651 |
|
|
* if it failed (non-NULL, contains a descriptive string). It does not affect |
| 652 |
|
|
* asar_geterrors. |
| 653 |
|
|
*/ |
| 654 |
|
3 |
EXPORT double asar_math(const char * math_, const char ** error) |
| 655 |
|
|
{ |
| 656 |
|
3 |
ns=""; |
| 657 |
|
3 |
namespace_list.reset(); |
| 658 |
|
3 |
sublabels.reset(); |
| 659 |
|
3 |
errored=false; |
| 660 |
|
3 |
ismath=true; |
| 661 |
|
3 |
initmathcore(); |
| 662 |
|
3 |
double rval=0; |
| 663 |
|
|
try |
| 664 |
|
|
{ |
| 665 |
4/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
|
10 |
rval = parse_math_expr(math_)->evaluate().get_double(); |
| 666 |
|
|
} |
| 667 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 |
catch(errfatal&) |
| 668 |
|
|
{ |
| 669 |
|
1 |
*error=matherror; |
| 670 |
|
1 |
} |
| 671 |
|
3 |
ismath=false; |
| 672 |
|
3 |
deinitmathcore(); |
| 673 |
|
3 |
return rval; |
| 674 |
|
3 |
} |
| 675 |
|
|
|
| 676 |
|
|
/* $EXPORT$ |
| 677 |
|
|
* Get a list of all the blocks written to the ROM by calls such as |
| 678 |
|
|
* asar_patch(). |
| 679 |
|
|
*/ |
| 680 |
|
3 |
EXPORT const struct writtenblockdata * asar_getwrittenblocks(int * count) |
| 681 |
|
|
{ |
| 682 |
|
3 |
*count = writtenblocks.count; |
| 683 |
|
3 |
return writtenblocks; |
| 684 |
|
|
} |
| 685 |
|
|
|
| 686 |
|
|
/* $EXPORT$ |
| 687 |
|
|
* Get the mapper currently used by Asar. |
| 688 |
|
|
*/ |
| 689 |
|
8 |
EXPORT enum mapper_t asar_getmapper() |
| 690 |
|
|
{ |
| 691 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 |
return mapper; |
| 692 |
|
|
} |
| 693 |
|
|
|
| 694 |
|
|
/* $EXPORT$ |
| 695 |
|
|
* Generates the contents of a symbols file for in a specific format. |
| 696 |
|
|
*/ |
| 697 |
|
1 |
EXPORT const char * asar_getsymbolsfile(const char* type){ |
| 698 |
2/7
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 |
symbolsfile = create_symbols_file(type, romCrc); |
| 699 |
|
1 |
return symbolsfile; |
| 700 |
|
|
} |
| 701 |
|
|
|
| 702 |
|
|
#if defined(__clang__) |
| 703 |
|
|
# pragma clang diagnostic pop |
| 704 |
|
|
#endif |
| 705 |
|
|
|