-
Notifications
You must be signed in to change notification settings - Fork 534
/
DumpStrings.1sc
127 lines (110 loc) · 2.9 KB
/
DumpStrings.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
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
126
127
//---------------------------------------------------------------------------
/*
010 Editor Script to dump strings found in the open file
2011/03/04 v0.0.1
Source code put in public domain by Didier Stevens, no Copyright
https://DidierStevens.com
Use at your own risk
History:
2011/03/02: start development with 010 Editor v3.1.3
2011/03/03: added UNICODE support
2011/03/04: added selection
Todo:
*/
//---------------------------------------------------------------------------
#define MIN_LENGTH 5
int IsPrintable(uchar ucByte)
{
return ucByte >= 0x20 && ucByte <= 0x7F;
}
void PrintASCIIString(int64 iStart, int64 iEnd)
{
Printf("A %08x: ", iStart);
while (iStart < iEnd)
Printf("%c", ReadByte(iStart++));
Printf("\n");
}
void SearchASCIIStrings(int64 iStart, int64 iSize)
{
int64 iIter;
int64 iStringStart = -1;
uchar ucByte;
for (iIter = iStart; iIter - iStart < iSize; iIter++)
{
ucByte = ReadUByte(iIter);
if (IsPrintable(ucByte))
{
if (iStringStart == -1)
iStringStart = iIter;
else if (iIter - iStart + 1 == iSize && iIter - iStringStart + 1 >= MIN_LENGTH)
PrintASCIIString(iStringStart, iIter + 1);
}
else if (iStringStart != -1)
{
if (iIter - iStringStart >= MIN_LENGTH)
PrintASCIIString(iStringStart, iIter);
iStringStart = -1;
}
}
}
void PrintUNICODEString(int64 iStart, int64 iLength)
{
Printf("U %08x: ", iStart);
while (iLength > 0)
{
Printf("%c", ReadByte(iStart));
iStart += 2;
iLength--;
}
Printf("\n");
}
int64 CheckForUNICODEString(int64 iStart, int64 iSize)
{
uchar ucByte1;
uchar ucByte2;
int64 iStringLength;
iStringLength = 0;
while (1)
{
ucByte1 = ReadUByte(iStart + iStringLength * 2);
if (!IsPrintable(ucByte1))
return iStringLength;
if (iStart + iStringLength * 2 + 1 >= iSize)
return iStringLength;
ucByte2 = ReadUByte(iStart + iStringLength * 2 + 1);
if (0 != ucByte2)
return iStringLength;
iStringLength++;
}
}
void SearchUNICODEStrings(int64 iStart, int64 iSize)
{
int64 iIter;
int64 iStringLength;
for (iIter = iStart; iIter - iStart < iSize; 0)
{
iStringLength = CheckForUNICODEString(iIter, iStart + iSize);
if (iStringLength >= MIN_LENGTH)
PrintUNICODEString(iIter, iStringLength);
if (0 == iStringLength)
iIter++;
else
iIter += iStringLength * 2;
}
}
void Main(void)
{
int64 iStart;
int64 iSize;
iSize = GetSelSize();
if (0 == iSize)
{
iStart = 0;
iSize = FileSize();
}
else
iStart = GetSelStart();
SearchASCIIStrings(iStart, iSize);
SearchUNICODEStrings(iStart, iSize);
}
Main();