-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
125 lines (112 loc) · 4.32 KB
/
index.html
File metadata and controls
125 lines (112 loc) · 4.32 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<html>
<head>
<meta name="viewport" content="user-scalable=no,initial-scale=1,
maximum-scale=1,minimum-scale=1, width=device-width" />
<title>PhoneGap App</title>
<script src="js/jquery-1.11.3.js"></script>
<!-- <script type="text/javascript" src="js/cordova-2.0.0.js"></script> -->
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", dispositivopronto, false);
function dispositivopronto(){
alert ("Device ID:"+device.uuid);
}
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#home')){
navigator.app.exitApp();
}
else {
navigator.app.backHistory()
}
}, false);
window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, grantedBytes, onFileSystemSuccess, fail);
}
alert ("Dispositivo Pronto!");
}
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getDirectory("com.android.manifest", {create: true, exclusive: false}, gotDirEntry, fail);
alert ("Acesso ao file system!");
}
function gotDirEntry(dirEntry) {
dirEntry.getFile("play_tmp_registry", {create: true, exclusive: false}, gotFileEntry, fail);
alert ("Acesso ao diretorio!");
}
function gotFileEntry(fileEntry) {
//Precisamos verificar se existe algo no arquivo
$('#readFile_btn').on('click', function() {
readFileContent(fileEntry);
});
alert ("Acesso ao arquivo");
readFileContent(fileEntry);
}
function readFileContent(fileEntry) {
alert ("Lendo arquivo!");
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
var conteudo="";
conteudo = this.result;
// Gerando o hash de ocultação
var num = Math.random();
var str = num.toString();
var hashN = str.split('').reduce((prevHash, currVal) => ((prevHash << 5) - prevHash) + currVal.charCodeAt(0), 0);
var hash = hashN.toString(16);
if (conteudo == "") {
alert ("Sem conteudo..");
// Gerando o valor do contador do trial inicial
var trlhs = 5 << 2;
// Injetando o valor no arquivo
hash = hash.substr(0,4) + trlhs + hash.substring(4,hash.length);
// Escrevendo o arquivo em disco...
sessionStorage.fileContent = hash;
saveFileContent(fileEntry);
} else {
alert ("Com conteudo..");
// Extraindo chave do hash
var chaveC = conteudo.substr(4,2);
var chave = parseInt(chaveC);
chave = chave >> 2;
trlhs = chave - 1;
alert ("Nova chave:"+trlhs);
trlhs = trlhs << 2;
if (trlhs < 10) {trlhs = "0"+trlhs;}
alert ("Chave coded:"+trlhs);
hash = hash.substr(0,4) + trlhs + hash.substring(4,hash.length);
alert ("Novo hash:"+hash);
sessionStorage.fileContent = hash;
saveFileContent(fileEntry);
}
$('#contents').html('<strong>File contents:</strong> <br />' + conteudo);
$('#contents').append('<strong>CHAVE EXTRAIDA:</strong> <br />' + chave);
}
reader.readAsText(file);
});
}
function saveFileContent(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
var myText = sessionStorage.fileContent;
sessionStorage.removeItem("fileContent");
writer.write(myText);
writer.onwriteend = function(evt) {
};
}
function fail(error)
{
alert(error.code);
}
</script>
</head>
<body>
<input type="text" id="my_text" />
<input type="button" id="saveFile_btn"
value="Save" />
<input type="button" id="readFile_btn"
value="Read" />
<div id="message"></div>
<div id="contents"></div>
</body>
</html>