forked from DidierStevens/DidierStevensSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-unicode-escape.1sc
64 lines (54 loc) · 1.71 KB
/
js-unicode-escape.1sc
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
/*
js-unicode-escape.1sc: 010 Editor Script File to %u encode selected bytes (little endian) for JavaScript's unescape("%uDEAD")
and copy the result to the clipboard
Version 0.0.3 2013/04/15
Source code put in public domain by Didier Stevens, no Copyright
https://DidierStevens.com
Use at your own risk
Shortcomings, or todo's ;-)
History:
2009/10/22: v0.0.1 start
2010/02/13: v0.0.2 included CopyStringToClipboard (requires v3.1 at least, since prior versions don't include function CopyStringToClipboard)
2013/04/15: v0.0.3 Refactoring & cleanup
*/
#define TITLE "js-unicode-escape"
void Main(void)
{
int iIter;
int iStart;
int iSize;
string sToClipboard;
string sTemp;
if (FileCount() == 0)
{
MessageBox(idOk, TITLE, "At least one file needs to be open.");
return;
}
// Initializes the variables
iSize = GetSelSize();
iStart = GetSelStart();
// Check that bytes were selected, otherwise process complete file
if (iSize == 0)
{
iSize = FileSize();
iStart = 0;
}
if (iSize > 10000 && MessageBox(idYes | idNo, TITLE, "It could take a long time to process %d bytes, do you want to continue?", iSize) == idNo)
return;
// Process and output bytes in %u format
Strcat(sToClipboard, "");
LittleEndian();
for (iIter = 0; iIter < iSize / 2; iIter++)
{
SPrintf(sTemp, "%%u%04x", ReadUShort(iStart + 2 * iIter));
Strcat(sToClipboard, sTemp);
}
if (iSize % 2 == 1)
{
SPrintf(sTemp, "%%u%04x", ReadUByte(iStart + iSize - 1));
Strcat(sToClipboard, sTemp);
}
CopyStringToClipboard(sToClipboard);
Printf("%s result copied to clipboard\n", TITLE);
}
Main();