forked from suleram/View8
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathv8dasm.cpp
71 lines (55 loc) · 2.06 KB
/
v8dasm.cpp
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
#include <fstream>
#include <iostream>
#include <string>
#include "libplatform/libplatform.h"
#include "v8.h"
#pragma comment(lib, "v8_libbase.lib")
#pragma comment(lib, "v8_libplatform.lib")
#pragma comment(lib, "wee8.lib")
#pragma comment(lib, "secur32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "dmoguids.lib")
#pragma comment(lib, "wmcodecdspuuid.lib")
#pragma comment(lib, "msdmo.lib")
#pragma comment(lib, "Strmiids.lib")
#pragma comment(lib, "DbgHelp.lib")
using namespace v8;
static Isolate* isolate = nullptr;
static void loadBytecode(uint8_t* bytecodeBuffer, int length) {
// Load code into code cache.
ScriptCompiler::CachedData* cached_data =
new ScriptCompiler::CachedData(bytecodeBuffer, length);
// Create dummy source.
ScriptOrigin origin(isolate, String::NewFromUtf8Literal(isolate, "code.jsc"));
ScriptCompiler::Source source(String::NewFromUtf8Literal(isolate, "\"ಠ_ಠ\""),
origin, cached_data);
// Compile code from code cache to print disassembly.
MaybeLocal<UnboundScript> script = ScriptCompiler::CompileUnboundScript(
isolate, &source, ScriptCompiler::kConsumeCodeCache);
}
static void readAllBytes(const std::string& file, std::vector<char>& buffer) {
std::ifstream infile(file, std::ios::binary);
infile.seekg(0, infile.end);
size_t length = infile.tellg();
infile.seekg(0, infile.beg);
if (length > 0) {
buffer.resize(length);
infile.read(&buffer[0], length);
}
}
int main(int argc, char* argv[]) {
V8::SetFlagsFromString("--no-lazy --no-flush-bytecode");
V8::InitializeICU();
std::unique_ptr<Platform> platform = platform::NewDefaultPlatform();
V8::InitializePlatform(platform.get());
V8::Initialize();
Isolate::CreateParams create_params;
create_params.array_buffer_allocator =
ArrayBuffer::Allocator::NewDefaultAllocator();
isolate = Isolate::New(create_params);
Isolate::Scope isolate_scope(isolate);
HandleScope scope(isolate);
std::vector<char> data;
readAllBytes(argv[1], data);
loadBytecode((uint8_t*)data.data(), data.size());
}