Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: runtime/bin/main.cc

Issue 3003583002: [VM, Precompiler] PoC Obfuscator (Closed)
Patch Set: Discard obfuscation map Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | runtime/vm/class_finalizer.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 // Global flag that is used to indicate that we want to compile all the 117 // Global flag that is used to indicate that we want to compile all the
118 // dart functions and not run anything. 118 // dart functions and not run anything.
119 static bool compile_all = false; 119 static bool compile_all = false;
120 static bool parse_all = false; 120 static bool parse_all = false;
121 121
122 // Global flag that is used to indicate that we want to use blobs/mmap instead 122 // Global flag that is used to indicate that we want to use blobs/mmap instead
123 // of assembly/shared libraries for precompilation. 123 // of assembly/shared libraries for precompilation.
124 static bool use_blobs = false; 124 static bool use_blobs = false;
125 125
126 // Global flag is used to indicate that we want to obfuscate identifiers.
127 static bool obfuscate = false;
128
126 // Global flag that is used to indicate that we want to trace resolution of 129 // Global flag that is used to indicate that we want to trace resolution of
127 // URIs and the loading of libraries, parts and scripts. 130 // URIs and the loading of libraries, parts and scripts.
128 static bool trace_loading = false; 131 static bool trace_loading = false;
129 132
130 static char* app_script_uri = NULL; 133 static char* app_script_uri = NULL;
131 static const uint8_t* app_isolate_snapshot_data = NULL; 134 static const uint8_t* app_isolate_snapshot_data = NULL;
132 static const uint8_t* app_isolate_snapshot_instructions = NULL; 135 static const uint8_t* app_isolate_snapshot_instructions = NULL;
133 136
134 static Dart_Isolate main_isolate = NULL; 137 static Dart_Isolate main_isolate = NULL;
135 138
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 static bool ProcessUseBlobsOption(const char* arg, 374 static bool ProcessUseBlobsOption(const char* arg,
372 CommandLineOptions* vm_options) { 375 CommandLineOptions* vm_options) {
373 ASSERT(arg != NULL); 376 ASSERT(arg != NULL);
374 if (*arg != '\0') { 377 if (*arg != '\0') {
375 return false; 378 return false;
376 } 379 }
377 use_blobs = true; 380 use_blobs = true;
378 return true; 381 return true;
379 } 382 }
380 383
384 static bool ProcessObfuscateOption(const char* arg,
385 CommandLineOptions* vm_options) {
386 ASSERT(arg != NULL);
387 if (*arg != '\0') {
388 return false;
389 }
390 obfuscate = true;
391 return true;
392 }
393
381 static bool ProcessSnapshotFilenameOption(const char* filename, 394 static bool ProcessSnapshotFilenameOption(const char* filename,
382 CommandLineOptions* vm_options) { 395 CommandLineOptions* vm_options) {
383 snapshot_filename = filename; 396 snapshot_filename = filename;
384 if (gen_snapshot_kind == kNone) { 397 if (gen_snapshot_kind == kNone) {
385 gen_snapshot_kind = kScript; // Default behavior. 398 gen_snapshot_kind = kScript; // Default behavior.
386 } 399 }
387 return true; 400 return true;
388 } 401 }
389 402
390 static bool ProcessSnapshotKindOption(const char* kind, 403 static bool ProcessSnapshotKindOption(const char* kind,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 {"--dfe=", ProcessFrontendOption}, 593 {"--dfe=", ProcessFrontendOption},
581 {"--kernel-binaries=", ProcessKernelBinariesOption}, 594 {"--kernel-binaries=", ProcessKernelBinariesOption},
582 #endif 595 #endif
583 {"--enable-vm-service", ProcessEnableVmServiceOption}, 596 {"--enable-vm-service", ProcessEnableVmServiceOption},
584 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, 597 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption},
585 {"--observe", ProcessObserveOption}, 598 {"--observe", ProcessObserveOption},
586 {"--snapshot=", ProcessSnapshotFilenameOption}, 599 {"--snapshot=", ProcessSnapshotFilenameOption},
587 {"--snapshot-kind=", ProcessSnapshotKindOption}, 600 {"--snapshot-kind=", ProcessSnapshotKindOption},
588 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, 601 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption},
589 {"--use-blobs", ProcessUseBlobsOption}, 602 {"--use-blobs", ProcessUseBlobsOption},
603 {"--obfuscate", ProcessObfuscateOption},
590 {"--save-compilation-trace=", ProcessSaveCompilationTraceOption}, 604 {"--save-compilation-trace=", ProcessSaveCompilationTraceOption},
591 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption}, 605 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption},
592 {"--save-feedback=", ProcessSaveFeedbackOption}, 606 {"--save-feedback=", ProcessSaveFeedbackOption},
593 {"--load-feedback=", ProcessLoadFeedbackOption}, 607 {"--load-feedback=", ProcessLoadFeedbackOption},
594 {"--trace-loading", ProcessTraceLoadingOption}, 608 {"--trace-loading", ProcessTraceLoadingOption},
595 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, 609 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption},
596 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, 610 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption},
597 {"--short_socket_read", ProcessShortSocketReadOption}, 611 {"--short_socket_read", ProcessShortSocketReadOption},
598 {"--short_socket_write", ProcessShortSocketWriteOption}, 612 {"--short_socket_write", ProcessShortSocketWriteOption},
599 {"--root-certs-file=", ProcessRootCertsFileOption}, 613 {"--root-certs-file=", ProcessRootCertsFileOption},
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename); 1421 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename);
1408 } 1422 }
1409 *size = file->Length(); 1423 *size = file->Length();
1410 *buffer = reinterpret_cast<uint8_t*>(malloc(*size)); 1424 *buffer = reinterpret_cast<uint8_t*>(malloc(*size));
1411 if (!file->ReadFully(*buffer, *size)) { 1425 if (!file->ReadFully(*buffer, *size)) {
1412 ErrorExit(kErrorExitCode, "Unable to read file %s\n", filename); 1426 ErrorExit(kErrorExitCode, "Unable to read file %s\n", filename);
1413 } 1427 }
1414 file->Release(); 1428 file->Release();
1415 } 1429 }
1416 1430
1431 static Dart_QualifiedFunctionName standalone_entry_points[] = {
1432 {"dart:_builtin", "::", "_getPrintClosure"},
1433 {"dart:_builtin", "::", "_getUriBaseClosure"},
1434 {"dart:_builtin", "::", "_libraryFilePath"},
1435 {"dart:_builtin", "::", "_resolveInWorkingDirectory"},
1436 {"dart:_builtin", "::", "_setPackageRoot"},
1437 {"dart:_builtin", "::", "_setPackagesMap"},
1438 {"dart:_builtin", "::", "_setWorkingDirectory"},
1439 {"dart:async", "::", "_setScheduleImmediateClosure"},
1440 {"dart:io", "::", "_getWatchSignalInternal"},
1441 {"dart:io", "::", "_makeDatagram"},
1442 {"dart:io", "::", "_makeUint8ListView"},
1443 {"dart:io", "::", "_setupHooks"},
1444 {"dart:io", "CertificateException", "CertificateException."},
1445 {"dart:io", "Directory", "Directory."},
1446 {"dart:io", "File", "File."},
1447 {"dart:io", "FileSystemException", "FileSystemException."},
1448 {"dart:io", "HandshakeException", "HandshakeException."},
1449 {"dart:io", "Link", "Link."},
1450 {"dart:io", "OSError", "OSError."},
1451 {"dart:io", "TlsException", "TlsException."},
1452 {"dart:io", "X509Certificate", "X509Certificate._"},
1453 {"dart:io", "_ExternalBuffer", "get:end"},
1454 {"dart:io", "_ExternalBuffer", "get:start"},
1455 {"dart:io", "_ExternalBuffer", "set:data"},
1456 {"dart:io", "_ExternalBuffer", "set:end"},
1457 {"dart:io", "_ExternalBuffer", "set:start"},
1458 {"dart:io", "_Platform", "set:_nativeScript"},
1459 {"dart:io", "_ProcessStartStatus", "set:_errorCode"},
1460 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"},
1461 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"},
1462 {"dart:io", "_SecureFilterImpl", "get:SIZE"},
1463 {"dart:io", "_SecureFilterImpl", "get:buffers"},
1464 {"dart:isolate", "::", "_getIsolateScheduleImmediateClosure"},
1465 {"dart:isolate", "::", "_setupHooks"},
1466 {"dart:isolate", "::", "_startMainIsolate"},
1467 {"dart:vmservice_io", "::", "main"},
1468 {NULL, NULL, NULL} // Must be terminated with NULL entries.
1469 };
1470
1417 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) { 1471 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
1418 // Call CreateIsolateAndSetup which creates an isolate and loads up 1472 // Call CreateIsolateAndSetup which creates an isolate and loads up
1419 // the specified application script. 1473 // the specified application script.
1420 char* error = NULL; 1474 char* error = NULL;
1421 bool is_main_isolate = true; 1475 bool is_main_isolate = true;
1422 int exit_code = 0; 1476 int exit_code = 0;
1423 char* isolate_name = BuildIsolateName(script_name, "main"); 1477 char* isolate_name = BuildIsolateName(script_name, "main");
1478 Dart_IsolateFlags flags;
1479 Dart_IsolateFlagsInitialize(&flags);
1480
1481 if (gen_snapshot_kind == kAppAOT) {
1482 flags.obfuscate = obfuscate;
1483 flags.entry_points = standalone_entry_points;
1484 }
1485
1424 Dart_Isolate isolate = CreateIsolateAndSetupHelper( 1486 Dart_Isolate isolate = CreateIsolateAndSetupHelper(
1425 is_main_isolate, script_name, "main", commandline_package_root, 1487 is_main_isolate, script_name, "main", commandline_package_root,
1426 commandline_packages_file, NULL, &error, &exit_code); 1488 commandline_packages_file, &flags, &error, &exit_code);
1427 if (isolate == NULL) { 1489 if (isolate == NULL) {
1428 delete[] isolate_name; 1490 delete[] isolate_name;
1429 Log::PrintErr("%s\n", error); 1491 Log::PrintErr("%s\n", error);
1430 free(error); 1492 free(error);
1431 error = NULL; 1493 error = NULL;
1432 Process::TerminateExitCodeHandler(); 1494 Process::TerminateExitCodeHandler();
1433 error = Dart_Cleanup(); 1495 error = Dart_Cleanup();
1434 if (error != NULL) { 1496 if (error != NULL) {
1435 Log::PrintErr("VM cleanup failed: %s\n", error); 1497 Log::PrintErr("VM cleanup failed: %s\n", error);
1436 free(error); 1498 free(error);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 if (parse_all) { 1552 if (parse_all) {
1491 result = Dart_ParseAll(); 1553 result = Dart_ParseAll();
1492 CHECK_RESULT(result); 1554 CHECK_RESULT(result);
1493 Dart_ExitScope(); 1555 Dart_ExitScope();
1494 // Shutdown the isolate. 1556 // Shutdown the isolate.
1495 Dart_ShutdownIsolate(); 1557 Dart_ShutdownIsolate();
1496 return false; 1558 return false;
1497 } 1559 }
1498 1560
1499 if (gen_snapshot_kind == kAppAOT) { 1561 if (gen_snapshot_kind == kAppAOT) {
1500 Dart_QualifiedFunctionName standalone_entry_points[] = {
1501 {"dart:_builtin", "::", "_getPrintClosure"},
1502 {"dart:_builtin", "::", "_getUriBaseClosure"},
1503 {"dart:_builtin", "::", "_libraryFilePath"},
1504 {"dart:_builtin", "::", "_resolveInWorkingDirectory"},
1505 {"dart:_builtin", "::", "_setPackageRoot"},
1506 {"dart:_builtin", "::", "_setPackagesMap"},
1507 {"dart:_builtin", "::", "_setWorkingDirectory"},
1508 {"dart:async", "::", "_setScheduleImmediateClosure"},
1509 {"dart:io", "::", "_getWatchSignalInternal"},
1510 {"dart:io", "::", "_makeDatagram"},
1511 {"dart:io", "::", "_makeUint8ListView"},
1512 {"dart:io", "::", "_setupHooks"},
1513 {"dart:io", "CertificateException", "CertificateException."},
1514 {"dart:io", "Directory", "Directory."},
1515 {"dart:io", "File", "File."},
1516 {"dart:io", "FileSystemException", "FileSystemException."},
1517 {"dart:io", "HandshakeException", "HandshakeException."},
1518 {"dart:io", "Link", "Link."},
1519 {"dart:io", "OSError", "OSError."},
1520 {"dart:io", "TlsException", "TlsException."},
1521 {"dart:io", "X509Certificate", "X509Certificate._"},
1522 {"dart:io", "_ExternalBuffer", "get:end"},
1523 {"dart:io", "_ExternalBuffer", "get:start"},
1524 {"dart:io", "_ExternalBuffer", "set:data"},
1525 {"dart:io", "_ExternalBuffer", "set:end"},
1526 {"dart:io", "_ExternalBuffer", "set:start"},
1527 {"dart:io", "_Platform", "set:_nativeScript"},
1528 {"dart:io", "_ProcessStartStatus", "set:_errorCode"},
1529 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"},
1530 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"},
1531 {"dart:io", "_SecureFilterImpl", "get:SIZE"},
1532 {"dart:io", "_SecureFilterImpl", "get:buffers"},
1533 {"dart:isolate", "::", "_getIsolateScheduleImmediateClosure"},
1534 {"dart:isolate", "::", "_setupHooks"},
1535 {"dart:isolate", "::", "_startMainIsolate"},
1536 {"dart:vmservice_io", "::", "main"},
1537 {NULL, NULL, NULL} // Must be terminated with NULL entries.
1538 };
1539
1540 uint8_t* feedback_buffer = NULL; 1562 uint8_t* feedback_buffer = NULL;
1541 intptr_t feedback_length = 0; 1563 intptr_t feedback_length = 0;
1542 if (load_feedback_filename != NULL) { 1564 if (load_feedback_filename != NULL) {
1543 File* file = File::Open(load_feedback_filename, File::kRead); 1565 File* file = File::Open(load_feedback_filename, File::kRead);
1544 if (file == NULL) { 1566 if (file == NULL) {
1545 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); 1567 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n");
1546 } 1568 }
1547 feedback_length = file->Length(); 1569 feedback_length = file->Length();
1548 feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length)); 1570 feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length));
1549 if (!file->ReadFully(feedback_buffer, feedback_length)) { 1571 if (!file->ReadFully(feedback_buffer, feedback_length)) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 Platform::Exit(Process::GlobalExitCode()); 1890 Platform::Exit(Process::GlobalExitCode());
1869 } 1891 }
1870 1892
1871 } // namespace bin 1893 } // namespace bin
1872 } // namespace dart 1894 } // namespace dart
1873 1895
1874 int main(int argc, char** argv) { 1896 int main(int argc, char** argv) {
1875 dart::bin::main(argc, argv); 1897 dart::bin::main(argc, argv);
1876 UNREACHABLE(); 1898 UNREACHABLE();
1877 } 1899 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | runtime/vm/class_finalizer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698