76
81
if (size < 0 || size > CLI_MAX_ALLOCATION) {
77
cli_warnmsg("bytecode: negative read size: %d\n", size);
82
cli_warnmsg("bytecode: negative read size: %d\n", size);
81
86
n = fmap_readn(ctx->fmap, data, ctx->off, size);
83
cli_dbgmsg("bcapi_read: fmap_readn failed (requested %d)\n", size);
84
cli_event_count(EV, BCEV_READ_ERR);
88
cli_dbgmsg("bcapi_read: fmap_readn failed (requested %d)\n", size);
89
cli_event_count(EV, BCEV_READ_ERR);
87
92
cli_event_int(EV, BCEV_OFFSET, ctx->off);
88
93
cli_event_fastdata(EV, BCEV_READ, data, size);
185
190
cli_ctx *cctx = (cli_ctx*)ctx->ctx;
187
cli_warnmsg("Bytecode API: called with negative length!\n");
192
cli_warnmsg("Bytecode API: called with negative length!\n");
191
196
if (!ctx->outfd) {
192
ctx->tempfile = cli_gentemp(cctx ? cctx->engine->tmpdir : NULL);
193
if (!ctx->tempfile) {
194
cli_dbgmsg("Bytecode API: Unable to allocate memory for tempfile\n");
195
cli_event_error_oom(EV, 0);
198
ctx->outfd = open(ctx->tempfile, O_RDWR|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
199
if (ctx->outfd == -1) {
201
cli_warnmsg("Bytecode API: Can't create file %s: %s\n", ctx->tempfile, cli_strerror(errno, err, sizeof(err)));
202
cli_event_error_str(EV, "cli_bcapi_write: Can't create temporary file");
206
cli_dbgmsg("bytecode opened new tempfile: %s\n", ctx->tempfile);
197
ctx->tempfile = cli_gentemp(cctx ? cctx->engine->tmpdir : NULL);
198
if (!ctx->tempfile) {
199
cli_dbgmsg("Bytecode API: Unable to allocate memory for tempfile\n");
200
cli_event_error_oom(EV, 0);
203
ctx->outfd = open(ctx->tempfile, O_RDWR|O_CREAT|O_EXCL|O_TRUNC|O_BINARY, 0600);
204
if (ctx->outfd == -1) {
206
cli_warnmsg("Bytecode API: Can't create file %s: %s\n", ctx->tempfile, cli_strerror(errno, err, sizeof(err)));
207
cli_event_error_str(EV, "cli_bcapi_write: Can't create temporary file");
211
cli_dbgmsg("bytecode opened new tempfile: %s\n", ctx->tempfile);
209
214
cli_event_fastdata(ctx->bc_events, BCEV_WRITE, data, len);
210
215
if (cli_checklimits("bytecode api", cctx, ctx->written + len, 0, 0))
212
217
res = cli_writen(ctx->outfd, data, len);
213
218
if (res > 0) ctx->written += res;
215
cli_warnmsg("Bytecode API: write failed: %s\n", cli_strerror(errno, err, sizeof(err)));
216
cli_event_error_str(EV, "cli_bcapi_write: write failed");
220
cli_warnmsg("Bytecode API: write failed: %s\n", cli_strerror(errno, err, sizeof(err)));
221
cli_event_error_str(EV, "cli_bcapi_write: write failed");
221
226
void cli_bytecode_context_set_trace(struct cli_bc_ctx* ctx, unsigned level,
222
bc_dbg_callback_trace trace,
223
bc_dbg_callback_trace_op trace_op,
224
bc_dbg_callback_trace_val trace_val,
225
bc_dbg_callback_trace_ptr trace_ptr)
227
bc_dbg_callback_trace trace,
228
bc_dbg_callback_trace_op trace_op,
229
bc_dbg_callback_trace_val trace_val,
230
bc_dbg_callback_trace_ptr trace_ptr)
227
232
ctx->trace = trace;
228
233
ctx->trace_op = trace_op;
269
274
uint32_t cli_bcapi_trace_op(struct cli_bc_ctx *ctx, const uint8_t *op, uint32_t col)
271
276
if (LIKELY(ctx->trace_level < trace_col))
273
278
if (ctx->trace_level&0xc0) {
275
/* func/scope changed and they needed param/location event */
276
ctx->trace(ctx, (ctx->trace_level&0x80) ? trace_func : trace_scope);
277
ctx->trace_level &= ~0xc0;
280
/* func/scope changed and they needed param/location event */
281
ctx->trace(ctx, (ctx->trace_level&0x80) ? trace_func : trace_scope);
282
ctx->trace_level &= ~0xc0;
279
284
if (LIKELY(ctx->trace_level < trace_col))
281
286
if (ctx->col != col) {
283
ctx->trace(ctx, trace_col);
288
ctx->trace(ctx, trace_col);
285
ctx->trace(ctx, trace_line);
290
ctx->trace(ctx, trace_line);
287
292
if (LIKELY(ctx->trace_level < trace_op))
289
294
if (ctx->trace_op && op)
290
ctx->trace_op(ctx, (const char*)op);
295
ctx->trace_op(ctx, (const char*)op);
294
299
uint32_t cli_bcapi_trace_value(struct cli_bc_ctx *ctx, const uint8_t* name, uint32_t value)
296
301
if (LIKELY(ctx->trace_level < trace_val))
298
303
if (ctx->trace_level&0x80) {
299
if ((ctx->trace_level&0x7f) < trace_param)
301
ctx->trace(ctx, trace_param);
304
if ((ctx->trace_level&0x7f) < trace_param)
306
ctx->trace(ctx, trace_param);
303
308
if (ctx->trace_val && name)
304
ctx->trace_val(ctx, (const char*)name, value);
309
ctx->trace_val(ctx, (const char*)name, value);
308
313
uint32_t cli_bcapi_trace_ptr(struct cli_bc_ctx *ctx, const uint8_t* ptr, uint32_t dummy)
310
315
if (LIKELY(ctx->trace_level < trace_val))
312
317
if (ctx->trace_level&0x80) {
313
if ((ctx->trace_level&0x7f) < trace_param)
315
ctx->trace(ctx, trace_param);
318
if ((ctx->trace_level&0x7f) < trace_param)
320
ctx->trace(ctx, trace_param);
317
322
if (ctx->trace_ptr)
318
ctx->trace_ptr(ctx, ptr);
323
ctx->trace_ptr(ctx, ptr);
336
341
static inline const char* cli_memmem(const char *haystack, unsigned hlen,
337
const unsigned char *needle, unsigned nlen)
342
const unsigned char *needle, unsigned nlen)
341
346
if (!needle || !haystack) {
346
return memchr(haystack, c, hlen);
351
return memchr(haystack, c, hlen);
348
353
while (hlen >= nlen) {
350
haystack = memchr(haystack, c, hlen - nlen + 1);
353
hlen -= haystack+1 - p;
355
if (!memcmp(p, needle, nlen-1))
355
haystack = memchr(haystack, c, hlen - nlen + 1);
358
hlen -= haystack+1 - p;
360
if (!memcmp(p, needle, nlen-1))
380
385
if (!map || len > sizeof(buf)/4 || len <= 0 || limit <= 0) {
381
cli_dbgmsg("bcapi_file_find_limit preconditions not met\n");
386
cli_dbgmsg("bcapi_file_find_limit preconditions not met\n");
386
391
cli_event_int(EV, BCEV_OFFSET, off);
387
392
cli_event_fastdata(EV, BCEV_FIND, data, len);
390
int32_t readlen = sizeof(buf);
391
if (off + readlen > limit) {
392
readlen = limit - off;
396
n = fmap_readn(map, buf, off, readlen);
397
if ((unsigned)n < len || n < 0)
399
p = cli_memmem(buf, n, data, len);
401
return off + p - buf;
395
int32_t readlen = sizeof(buf);
396
if (off + readlen > limit) {
397
readlen = limit - off;
401
n = fmap_readn(map, buf, off, readlen);
402
if ((unsigned)n < len || n < 0)
404
p = cli_memmem(buf, n, data, len);
406
return off + p - buf;
438
443
v = cli_malloc(size);
441
cli_event_error_oom(EV, size);
446
cli_event_error_oom(EV, size);
445
450
int32_t cli_bcapi_get_pe_section(struct cli_bc_ctx *ctx, void* section, uint32_t num)
447
452
if (num < ctx->hooks.pedata->nsections) {
448
memcpy(section, &ctx->sections[num], sizeof(struct cli_exe_section));
453
memcpy(section, &ctx->sections[num], sizeof(struct cli_exe_section));
454
459
int32_t cli_bcapi_fill_buffer(struct cli_bc_ctx *ctx, uint8_t* buf,
455
uint32_t buflen, uint32_t filled,
456
uint32_t pos, uint32_t fill)
460
uint32_t buflen, uint32_t filled,
461
uint32_t pos, uint32_t fill)
458
463
int32_t res, remaining, tofill;
459
464
if (!buf || !buflen || buflen > CLI_MAX_ALLOCATION || filled > buflen) {
460
cli_dbgmsg("fill_buffer1\n");
465
cli_dbgmsg("fill_buffer1\n");
464
469
if (ctx->off >= ctx->file_size) {
465
cli_dbgmsg("fill_buffer2\n");
470
cli_dbgmsg("fill_buffer2\n");
469
474
remaining = filled - pos;
471
if (!CLI_ISCONTAINED(buf, buflen, buf+pos, remaining)) {
472
cli_dbgmsg("fill_buffer3\n");
476
memmove(buf, buf+pos, remaining);
476
if (!CLI_ISCONTAINED(buf, buflen, buf+pos, remaining)) {
477
cli_dbgmsg("fill_buffer3\n");
481
memmove(buf, buf+pos, remaining);
478
483
tofill = buflen - remaining;
479
484
if (!CLI_ISCONTAINED(buf, buflen, buf+remaining, tofill)) {
480
cli_dbgmsg("fill_buffer4\n");
485
cli_dbgmsg("fill_buffer4\n");
484
489
res = cli_bcapi_read(ctx, buf+remaining, tofill);
486
cli_dbgmsg("fill_buffer5\n");
491
cli_dbgmsg("fill_buffer5\n");
490
495
return remaining + res;
509
514
cli_dbgmsg("bytecode: scanning extracted file %s\n", ctx->tempfile);
510
515
cctx = (cli_ctx*)ctx->ctx;
512
cli_file_t current = cctx->container_type;
513
if (ctx->containertype != CL_TYPE_ANY)
514
cctx->container_type = ctx->containertype;
516
res = cli_magic_scandesc(ctx->outfd, cctx);
518
cctx->container_type = current;
519
if (res == CL_VIRUS) {
520
ctx->virname = cli_get_last_virus(cctx);
517
cli_file_t current = cctx->container_type;
518
if (ctx->containertype != CL_TYPE_ANY)
519
cctx->container_type = ctx->containertype;
521
res = cli_magic_scandesc(ctx->outfd, cctx);
523
cctx->container_type = current;
524
if (res == CL_VIRUS) {
525
ctx->virname = cli_get_last_virus(cctx);
524
529
if ((cctx && cctx->engine->keeptmp) ||
525
(ftruncate(ctx->outfd, 0) == -1)) {
530
(ftruncate(ctx->outfd, 0) == -1)) {
528
if (!(cctx && cctx->engine->keeptmp) && ctx->tempfile)
529
cli_unlink(ctx->tempfile);
531
ctx->tempfile = NULL;
533
if (!(cctx && cctx->engine->keeptmp) && ctx->tempfile)
534
cli_unlink(ctx->tempfile);
536
ctx->tempfile = NULL;
534
539
cli_dbgmsg("bytecode: extracting new file with id %u\n", id);
545
550
if ((radix != 10 && radix != 16) || !ctx->fmap)
547
552
cli_event_int(EV, BCEV_OFFSET, ctx->off);
548
553
while ((p = fmap_need_off_once(ctx->fmap, ctx->off, BUF))) {
549
for (i=0;i<BUF;i++) {
550
if ((p[i] >= '0' && p[i] <= '9') || (radix == 16 && ((p[i] >= 'a' && p[i] <= 'f') || (p[i] >= 'A' && p[i] <= 'F')))) {
552
p = fmap_need_ptr_once(ctx->fmap, p+i, 16);
555
result = strtoul(p, &endptr, radix);
556
ctx->off += i + (endptr - p);
554
for (i=0;i<BUF;i++) {
555
if ((p[i] >= '0' && p[i] <= '9') || (radix == 16 && ((p[i] >= 'a' && p[i] <= 'f') || (p[i] >= 'A' && p[i] <= 'F')))) {
557
p = fmap_need_ptr_once(ctx->fmap, p+i, 16);
560
result = strtoul(p, &endptr, radix);
561
ctx->off += i + (endptr - p);
725
730
struct bc_buffer *b = get_buffer(ctx, id);
729
if (b->write_cursor <= b->read_cursor)
731
if (b->read_cursor + amount > b->write_cursor)
732
b->read_cursor = b->write_cursor;
734
b->read_cursor += amount;
735
if (b->read_cursor >= b->size &&
736
b->write_cursor >= b->size)
737
b->read_cursor = b->write_cursor = 0;
734
if (b->write_cursor <= b->read_cursor)
736
if (b->read_cursor + amount > b->write_cursor)
737
b->read_cursor = b->write_cursor;
739
b->read_cursor += amount;
740
if (b->read_cursor >= b->size &&
741
b->write_cursor >= b->size)
742
b->read_cursor = b->write_cursor = 0;
740
745
b->read_cursor += amount;
792
797
struct bc_inflate *b;
793
798
unsigned n = ctx->ninflates + 1;
794
799
if (!get_buffer(ctx, from) || !get_buffer(ctx, to)) {
795
cli_dbgmsg("bytecode api: inflate_init: invalid buffers!\n");
800
cli_dbgmsg("bytecode api: inflate_init: invalid buffers!\n");
798
803
memset(&stream, 0, sizeof(stream));
799
804
ret = inflateInit2(&stream, windowBits);
802
cli_dbgmsg("bytecode api: inflateInit2: out of memory!\n");
804
case Z_VERSION_ERROR:
805
cli_dbgmsg("bytecode api: inflateinit2: zlib version error!\n");
808
cli_dbgmsg("bytecode api: inflateinit2: zlib stream error!\n");
813
cli_dbgmsg("bytecode api: inflateInit2: unknown error %d\n", ret);
807
cli_dbgmsg("bytecode api: inflateInit2: out of memory!\n");
809
case Z_VERSION_ERROR:
810
cli_dbgmsg("bytecode api: inflateinit2: zlib version error!\n");
813
cli_dbgmsg("bytecode api: inflateinit2: zlib stream error!\n");
818
cli_dbgmsg("bytecode api: inflateInit2: unknown error %d\n", ret);
817
822
b = cli_realloc(ctx->inflates, sizeof(*ctx->inflates)*n);
822
827
ctx->inflates = b;
823
828
ctx->ninflates = n;
843
848
unsigned avail_in_orig, avail_out_orig;
844
849
struct bc_inflate *b = get_inflate(ctx, id);
845
850
if (!b || b->from == -1 || b->to == -1)
848
853
b->stream.avail_in = avail_in_orig =
849
cli_bcapi_buffer_pipe_read_avail(ctx, b->from);
854
cli_bcapi_buffer_pipe_read_avail(ctx, b->from);
851
856
b->stream.next_in = (void*)cli_bcapi_buffer_pipe_read_get(ctx, b->from,
854
859
b->stream.avail_out = avail_out_orig =
855
cli_bcapi_buffer_pipe_write_avail(ctx, b->to);
860
cli_bcapi_buffer_pipe_write_avail(ctx, b->to);
857
862
b->stream.next_out = cli_bcapi_buffer_pipe_write_get(ctx, b->to,
858
b->stream.avail_out);
863
b->stream.avail_out);
860
865
if (!b->stream.avail_in || !b->stream.avail_out || !b->stream.next_in || !b->stream.next_out)
862
867
/* try hard to extract data, skipping over corrupted data */
865
ret = inflate(&b->stream, Z_NO_FLUSH);
866
if (ret == Z_DATA_ERROR) {
867
cli_dbgmsg("bytecode api: inflate at %lu: %s, trying to recover\n", b->stream.total_in,
873
ret = inflateSync(&b->stream);
875
cli_dbgmsg("bytecode api: successfully recovered inflate stream\n");
870
ret = inflate(&b->stream, Z_NO_FLUSH);
871
if (ret == Z_DATA_ERROR) {
872
cli_dbgmsg("bytecode api: inflate at %lu: %s, trying to recover\n", b->stream.total_in,
878
ret = inflateSync(&b->stream);
880
cli_dbgmsg("bytecode api: successfully recovered inflate stream\n");
882
887
cli_bcapi_buffer_pipe_read_stopped(ctx, b->from, avail_in_orig - b->stream.avail_in);
883
888
cli_bcapi_buffer_pipe_write_stopped(ctx, b->to, avail_out_orig - b->stream.avail_out);
885
890
if (ret == Z_MEM_ERROR) {
886
cli_dbgmsg("bytecode api: out of memory!\n");
887
cli_bcapi_inflate_done(ctx, id);
891
cli_dbgmsg("bytecode api: out of memory!\n");
892
cli_bcapi_inflate_done(ctx, id);
890
895
if (ret == Z_STREAM_END) {
891
cli_bcapi_inflate_done(ctx, id);
896
cli_bcapi_inflate_done(ctx, id);
893
898
if (ret == Z_BUF_ERROR) {
894
cli_dbgmsg("bytecode api: buffer error!\n");
899
cli_dbgmsg("bytecode api: buffer error!\n");
968
973
cli_ctx *cctx = ctx->ctx;
969
974
struct bc_jsnorm *b = get_jsnorm(ctx, id);
970
975
if (!b || b->from == -1 || !b->state)
973
978
avail = cli_bcapi_buffer_pipe_read_avail(ctx, b->from);
974
979
in = cli_bcapi_buffer_pipe_read_get(ctx, b->from, avail);
975
980
if (!avail || !in)
977
982
if (cctx && cli_checklimits("bytecode js api", cctx, ctx->jsnormwritten + avail, 0, 0))
979
984
cli_bcapi_buffer_pipe_read_stopped(ctx, b->from, avail);
980
985
cli_js_process_buffer(b->state, (char*)in, avail);
1046
1051
f = c*cos((double)a/b);
1047
1052
return (int32_t)myround(f);
1050
1055
int32_t cli_bcapi_memstr(struct cli_bc_ctx *ctx, const uint8_t* h, int32_t hs,
1051
const uint8_t*n, int32_t ns)
1056
const uint8_t*n, int32_t ns)
1053
1058
const uint8_t *s;
1054
1059
if (!h || !n || hs < 0 || ns < 0) {
1058
1063
cli_event_fastdata(EV, BCEV_MEM_1, h, hs);
1059
1064
cli_event_fastdata(EV, BCEV_MEM_2, n, ns);
1060
1065
s = (const uint8_t*) cli_memstr((const char*)h, hs, (const char*)n, ns);
1266
1271
if (ctx->extracted_file_input == extracted_file)
1268
1273
if (!extracted_file) {
1269
cli_dbgmsg("bytecode api: input switched back to main file\n");
1270
ctx->fmap = ctx->save_map;
1271
ctx->extracted_file_input = 0;
1274
cli_dbgmsg("bytecode api: input switched back to main file\n");
1275
ctx->fmap = ctx->save_map;
1276
ctx->extracted_file_input = 0;
1274
1279
if (ctx->outfd < 0)
1276
1281
map = fmap(ctx->outfd, 0, 0);
1278
cli_warnmsg("can't mmap() extracted temporary file %s\n", ctx->tempfile);
1283
cli_warnmsg("can't mmap() extracted temporary file %s\n", ctx->tempfile);
1281
1286
ctx->save_map = ctx->fmap;
1282
1287
cli_bytecode_context_setfile(ctx, map);
1298
1303
uint32_t cli_bcapi_disable_bytecode_if(struct cli_bc_ctx *ctx , const int8_t* reason, uint32_t len, uint32_t cond)
1300
1305
if (ctx->bc->kind != BC_STARTUP) {
1301
cli_dbgmsg("Bytecode must be BC_STARTUP to call disable_bytecode_if\n");
1306
cli_dbgmsg("Bytecode must be BC_STARTUP to call disable_bytecode_if\n");
1305
return ctx->bytecode_disable_status;
1310
return ctx->bytecode_disable_status;
1306
1311
if (*reason == '^')
1307
cli_warnmsg("Bytecode: disabling completely because %s\n", reason+1);
1312
cli_warnmsg("Bytecode: disabling completely because %s\n", reason+1);
1309
cli_dbgmsg("Bytecode: disabling completely because %s\n", reason);
1314
cli_dbgmsg("Bytecode: disabling completely because %s\n", reason);
1310
1315
ctx->bytecode_disable_status = 2;
1311
1316
return ctx->bytecode_disable_status;
1314
1319
uint32_t cli_bcapi_disable_jit_if(struct cli_bc_ctx *ctx , const int8_t* reason, uint32_t len, uint32_t cond)
1316
1321
if (ctx->bc->kind != BC_STARTUP) {
1317
cli_dbgmsg("Bytecode must be BC_STARTUP to call disable_jit_if\n");
1322
cli_dbgmsg("Bytecode must be BC_STARTUP to call disable_jit_if\n");
1321
return ctx->bytecode_disable_status;
1326
return ctx->bytecode_disable_status;
1322
1327
if (*reason == '^')
1323
cli_warnmsg("Bytecode: disabling JIT because %s\n", reason+1);
1328
cli_warnmsg("Bytecode: disabling JIT because %s\n", reason+1);
1325
cli_dbgmsg("Bytecode: disabling JIT because %s\n", reason);
1330
cli_dbgmsg("Bytecode: disabling JIT because %s\n", reason);
1326
1331
if (ctx->bytecode_disable_status != 2) /* no reenabling */
1327
ctx->bytecode_disable_status = 1;
1332
ctx->bytecode_disable_status = 1;
1328
1333
return ctx->bytecode_disable_status;
1331
1336
int32_t cli_bcapi_version_compare(struct cli_bc_ctx *ctx , const uint8_t* lhs, uint32_t lhs_len,
1332
const uint8_t* rhs, uint32_t rhs_len)
1337
const uint8_t* rhs, uint32_t rhs_len)
1334
1339
unsigned i = 0, j = 0;
1335
1340
unsigned long li=0, ri=0;
1337
while (i < lhs_len && j < rhs_len && lhs[i] == rhs[j] &&
1338
!isdigit(lhs[i]) && !isdigit(rhs[j])) {
1341
if (i == lhs_len && j == rhs_len)
1347
if (!isdigit(lhs[i]) || !isdigit(rhs[j]))
1348
return lhs[i] < rhs[j] ? -1 : 1;
1349
while (isdigit(lhs[i]) && i < lhs_len)
1350
li = 10*li + (lhs[i++] - '0');
1351
while (isdigit(rhs[j]) && j < rhs_len)
1352
ri = 10*ri + (rhs[j++] - '0');
1342
while (i < lhs_len && j < rhs_len && lhs[i] == rhs[j] &&
1343
!isdigit(lhs[i]) && !isdigit(rhs[j])) {
1346
if (i == lhs_len && j == rhs_len)
1352
if (!isdigit(lhs[i]) || !isdigit(rhs[j]))
1353
return lhs[i] < rhs[j] ? -1 : 1;
1354
while (isdigit(lhs[i]) && i < lhs_len)
1355
li = 10*li + (lhs[i++] - '0');
1356
while (isdigit(rhs[j]) && j < rhs_len)
1357
ri = 10*ri + (rhs[j++] - '0');
1363
1368
uint8_t v = (value >> shift)&mask;
1364
1369
/* q == mask -> ANY */
1365
1370
if (q == v || q == mask)
1370
1375
uint32_t cli_bcapi_check_platform(struct cli_bc_ctx *ctx , uint32_t a, uint32_t b , uint32_t c)
1373
check_bits(a, ctx->env->platform_id_a, 24, 0xff) &&
1374
check_bits(a, ctx->env->platform_id_a, 20, 0xf) &&
1375
check_bits(a, ctx->env->platform_id_a, 16, 0xf) &&
1376
check_bits(a, ctx->env->platform_id_a, 8, 0xff) &&
1377
check_bits(a, ctx->env->platform_id_a, 0, 0xff) &&
1378
check_bits(b, ctx->env->platform_id_b, 28, 0xf) &&
1379
check_bits(b, ctx->env->platform_id_b, 24, 0xf) &&
1380
check_bits(b, ctx->env->platform_id_b, 16, 0xff) &&
1381
check_bits(b, ctx->env->platform_id_b, 8, 0xff) &&
1382
check_bits(b, ctx->env->platform_id_b, 0, 0xff) &&
1383
check_bits(c, ctx->env->platform_id_c, 24, 0xff) &&
1384
check_bits(c, ctx->env->platform_id_c, 16, 0xff) &&
1385
check_bits(c, ctx->env->platform_id_c, 8, 0xff) &&
1386
check_bits(c, ctx->env->platform_id_c, 0, 0xff);
1378
check_bits(a, ctx->env->platform_id_a, 24, 0xff) &&
1379
check_bits(a, ctx->env->platform_id_a, 20, 0xf) &&
1380
check_bits(a, ctx->env->platform_id_a, 16, 0xf) &&
1381
check_bits(a, ctx->env->platform_id_a, 8, 0xff) &&
1382
check_bits(a, ctx->env->platform_id_a, 0, 0xff) &&
1383
check_bits(b, ctx->env->platform_id_b, 28, 0xf) &&
1384
check_bits(b, ctx->env->platform_id_b, 24, 0xf) &&
1385
check_bits(b, ctx->env->platform_id_b, 16, 0xff) &&
1386
check_bits(b, ctx->env->platform_id_b, 8, 0xff) &&
1387
check_bits(b, ctx->env->platform_id_b, 0, 0xff) &&
1388
check_bits(c, ctx->env->platform_id_c, 24, 0xff) &&
1389
check_bits(c, ctx->env->platform_id_c, 16, 0xff) &&
1390
check_bits(c, ctx->env->platform_id_c, 8, 0xff) &&
1391
check_bits(c, ctx->env->platform_id_c, 0, 0xff);
1388
cli_dbgmsg("check_platform(0x%08x,0x%08x,0x%08x) = match\n",a,b,c);
1393
cli_dbgmsg("check_platform(0x%08x,0x%08x,0x%08x) = match\n",a,b,c);
1393
1398
int cli_bytecode_context_setpdf(struct cli_bc_ctx *ctx, unsigned phase,
1395
struct pdf_obj *objs, uint32_t *pdf_flags,
1396
uint32_t pdfsize, uint32_t pdfstartoff)
1400
struct pdf_obj *objs, uint32_t *pdf_flags,
1401
uint32_t pdfsize, uint32_t pdfstartoff)
1398
1403
ctx->pdf_nobjs = nobjs;
1399
1404
ctx->pdf_objs = objs;
1458
1463
uint32_t size = cli_bcapi_pdf_getobjsize(ctx, objidx);
1459
1464
if (amount > size)
1461
1466
return fmap_need_off(ctx->fmap, ctx->pdf_objs[objidx].start, amount);
1464
1469
int32_t cli_bcapi_pdf_getobjid(struct cli_bc_ctx *ctx , int32_t objidx)
1466
1471
if (!ctx->pdf_phase ||
1467
objidx >= ctx->pdf_nobjs)
1472
objidx >= ctx->pdf_nobjs)
1469
1474
return ctx->pdf_objs[objidx].id;
1472
1477
int32_t cli_bcapi_pdf_getobjflags(struct cli_bc_ctx *ctx , int32_t objidx)
1474
1479
if (!ctx->pdf_phase ||
1475
objidx >= ctx->pdf_nobjs)
1480
objidx >= ctx->pdf_nobjs)
1477
1482
return ctx->pdf_objs[objidx].flags;
1480
1485
int32_t cli_bcapi_pdf_setobjflags(struct cli_bc_ctx *ctx , int32_t objidx, int32_t flags)
1482
1487
if (!ctx->pdf_phase ||
1483
objidx >= ctx->pdf_nobjs)
1488
objidx >= ctx->pdf_nobjs)
1485
1490
cli_dbgmsg("cli_pdf: bytecode setobjflags %08x -> %08x\n",
1486
ctx->pdf_objs[objidx].flags,
1491
ctx->pdf_objs[objidx].flags,
1488
1493
ctx->pdf_objs[objidx].flags = flags;