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

Unified Diff: runtime/vm/object.cc

Issue 3003583002: [VM, Precompiler] PoC Obfuscator (Closed)
Patch Set: Fix bad refactoring in NewAtomicRename Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 04c4e6824dc5cc8a75cef79673ad47d4fa45a660..cb675ef5f1fd05f7a7abc08c07cfd07f84ba9a88 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -7453,7 +7453,8 @@ void Function::SetDeoptReasonForAll(intptr_t deopt_id,
}
bool Function::CheckSourceFingerprint(const char* prefix, int32_t fp) const {
- if ((kernel_offset() <= 0) && (SourceFingerprint() != fp)) {
+ if (!Isolate::Current()->obfuscate() && (kernel_offset() <= 0) &&
+ (SourceFingerprint() != fp)) {
const bool recalculatingFingerprints = false;
if (recalculatingFingerprints) {
// This output can be copied into a file, then used with sed
@@ -8656,19 +8657,29 @@ class CompressedTokenStreamData : public Scanner::TokenCollector {
static const bool kPrintTokenObjects = false;
CompressedTokenStreamData(const GrowableObjectArray& ta,
- CompressedTokenMap* map)
+ CompressedTokenMap* map,
+ Obfuscator* obfuscator)
: buffer_(NULL),
stream_(&buffer_, Reallocate, kInitialBufferSize),
token_objects_(ta),
tokens_(map),
+ str_(String::Handle()),
value_(Object::Handle()),
fresh_index_smi_(Smi::Handle()),
- num_tokens_collected_(0) {}
+ num_tokens_collected_(0),
+ obfuscator_(obfuscator) {}
virtual ~CompressedTokenStreamData() {}
virtual void AddToken(const Scanner::TokenDescriptor& token) {
if (token.kind == Token::kIDENT) { // Identifier token.
AddIdentToken(*token.literal);
+ } else if (token.kind == Token::kINTERPOL_VAR) {
+ str_ = token.literal->raw();
+ str_ = obfuscator_->Rename(str_);
+
+ Scanner::TokenDescriptor token_copy = token;
+ token_copy.literal = &str_;
+ AddLiteralToken(token_copy);
} else if (Token::NeedsLiteralToken(token.kind)) { // Literal token.
AddLiteralToken(token);
} else { // Keyword, pseudo keyword etc.
@@ -8691,15 +8702,17 @@ class CompressedTokenStreamData : public Scanner::TokenCollector {
void AddIdentToken(const String& ident) {
ASSERT(ident.IsSymbol());
const intptr_t fresh_index = token_objects_.Length();
+ str_ = ident.raw();
+ str_ = obfuscator_->Rename(str_);
fresh_index_smi_ = Smi::New(fresh_index);
intptr_t index = Smi::Value(
Smi::RawCast(tokens_->InsertOrGetValue(ident, fresh_index_smi_)));
if (index == fresh_index) {
- token_objects_.Add(ident);
+ token_objects_.Add(str_);
if (kPrintTokenObjects) {
int iid = Isolate::Current()->main_port() % 1024;
- OS::Print("ident %03x %p <%s>\n", iid, ident.raw(),
- ident.ToCString());
+ OS::Print("%03x ident <%s -> %s>\n", iid, ident.ToCString(),
+ str_.ToCString());
}
}
WriteIndex(index);
@@ -8762,9 +8775,11 @@ class CompressedTokenStreamData : public Scanner::TokenCollector {
WriteStream stream_;
const GrowableObjectArray& token_objects_;
CompressedTokenMap* tokens_;
+ String& str_;
Object& value_;
Smi& fresh_index_smi_;
intptr_t num_tokens_collected_;
+ Obfuscator* obfuscator_;
DISALLOW_COPY_AND_ASSIGN(CompressedTokenStreamData);
};
@@ -8794,8 +8809,9 @@ RawTokenStream* TokenStream::New(const String& source,
token_objects_map = HashTables::New<CompressedTokenMap>(
kInitialPrivateCapacity, Heap::kOld);
}
+ Obfuscator obfuscator(thread, private_key);
CompressedTokenMap map(token_objects_map.raw());
- CompressedTokenStreamData data(token_objects, &map);
+ CompressedTokenStreamData data(token_objects, &map, &obfuscator);
Scanner scanner(source, private_key);
scanner.ScanAll(&data);
INC_STAT(thread, num_tokens_scanned, data.NumTokens());
@@ -9236,6 +9252,7 @@ void Script::Tokenize(const String& private_key, bool use_shared_tokens) const {
// Already tokenized.
return;
}
+
// Get the source, scan and allocate the token stream.
VMTagScope tagScope(thread, VMTag::kCompileScannerTagId);
CSTAT_TIMER_SCOPE(thread, scanner_timer);
@@ -9766,11 +9783,19 @@ void Library::set_num_imports(intptr_t value) const {
StoreNonPointer(&raw_ptr()->num_imports_, value);
}
+void Library::set_name(const String& name) const {
+ ASSERT(name.IsSymbol());
+ StorePointer(&raw_ptr()->name_, name.raw());
+}
+
+void Library::set_url(const String& name) const {
+ StorePointer(&raw_ptr()->url_, name.raw());
+}
+
void Library::SetName(const String& name) const {
// Only set name once.
ASSERT(!Loaded());
- ASSERT(name.IsSymbol());
- StorePointer(&raw_ptr()->name_, name.raw());
+ set_name(name);
}
void Library::SetLoadInProgress() const {
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698