Menu

[r11]: / trunk / SWFInvestigator / src / utils / StringToBinFile.mxml  Maximize  Restore  History

Download this file

376 lines (329 with data), 14.1 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?xml version="1.0" encoding="utf-8"?>
<s:Window xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="770" height="662" backgroundColor="#FFFFFF" showStatusBar="false" title="Binary Editor">
<fx:Script>
<![CDATA[
/****************************************************************************
* ADOBE SYSTEMS INCORPORATED
* Copyright 2012 Adobe Systems Incorporated and it’s licensors
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
* ****************************************************************************/
import hexEditor.HexValidator;
import hexEditor.HexViewer;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import osUtils.FileActionEvent;
import osUtils.FileActions;
import spark.components.gridClasses.CellPosition;
include '../hexEditor/gridEventHandlers.as';
/**
* A local copy of the SWF Bytes
*/
public var swfBytes:ByteArray = new ByteArray();
[Bindable]
private var hvFileTagCollection:ArrayCollection;
[Bindable]
public var HV:HexViewer = new hexEditor.HexViewer(true);
[Bindable]
public var hvSearchType:ArrayCollection = new ArrayCollection(
[ {label:"Hex", data:"findHex"},
{label:"String", data:"findString"} ]);
private var fActions:FileActions;
/**
* @private
* Converts a string of integers to hex
* Expected format is "12345678, 87654321"
*/
private function convertToHex():void {
var rexp:RegExp = /^[0-9\, ]+$/g;
if (!rexp.test(this.sourceText.text)) {
this.errorBox.text = "String contains invalid characters";
return;
} else if (this.sourceText.text.length == 0) {
this.errorBox.text = "Please enter data into Source Text";
return;
}
swfBytes.clear();
var s:String;
var l:int = 0;
var j:int = 0;
if (this.sourceText.text.indexOf(",") > 0) {
var tmp:Array = this.sourceText.text.split(/[\, ]+/);
for (var i:int = 0; i < tmp.length; i++) {
s = uint(tmp[i]).toString(16);
if (s.length != 8) {
l = 0;
j = 8 - s.length;
while (l < j) {
s = "0" + s;
l++;
}
}
for (j = 0; j < s.length; j += 2) {
swfBytes.writeByte(int("0x" + s.charAt(j) + s.charAt(j+1)));
}
}
} else {
s = uint(this.sourceText.text).toString(16);
if (s.length != 8) {
j = 8 - s.length;
while (l < j) {
s = "0" + s;
l++;
}
}
for (j = 0; j < s.length; j += 2) {
swfBytes.writeByte(int("0x" + s.charAt(j) + s.charAt(j+1)));
}
}
this.HV.initViewer(this.swfBytes);
HV.updateHexArray();
}
/**
* @private
* Compress all the data in the byte array and re-display
*/
private function compressData():void {
this.swfBytes.compress();
this.HV.initViewer(this.swfBytes);
HV.updateHexArray();
}
/**
* @private
* Uncompress all the data in the byte array and re-display
*/
private function uncompressData():void {
try {
this.swfBytes.uncompress();
this.HV.initViewer(this.swfBytes);
HV.updateHexArray();
} catch (e:Error) {
this.errorBox.text = e.message;
}
}
/**
* @private
* XOR all the data in the byte array and re-display
*/
private function xorData():void {
var x_val:int;
if (this.xorValue.text.indexOf("x") > 0) {
x_val = int (this.xorValue.text);
} else {
x_val = parseInt(this.xorValue.text);
}
for (var i:int = 0; i < this.swfBytes.length; i++) {
this.swfBytes[i] = this.swfBytes[i] ^ x_val;
}
this.HV.initViewer(this.swfBytes);
HV.updateHexArray();
}
/**
* @private
* Copies the hex string to the data grid
* Supported formats include "0x44445555", "44555544", "44,55" or "0x44,0x55"
*/
private function copyToGrid():void {
var sText:String = this.sourceText.text;
var rexp:RegExp = /^[0-9A-Fa-f\, x]+$/g;
if (!rexp.test(sText)) {
this.errorBox.text = "String contains invalid characters";
return;
} else if (sText.length == 0) {
this.errorBox.text = "Please enter data into Source Text";
return;
}
swfBytes.clear();
var j:int = 0;
if (sText.indexOf(",") > 0) {
var tmp:Array = sText.split(/[ \,]+/);
for (var i:int = 0; i < tmp.length; i++) {
if (tmp[i].length == 2) {
swfBytes.writeByte(int("0x" + tmp[i]));
} else if (tmp[i].length % 2 == 0) {
for (j = 0; j < tmp[i].length; j += 2) {
if (tmp[i].charAt(j+1) != "x") {
swfBytes.writeByte(int("0x" + tmp[i].charAt(j) + tmp[i].charAt(j+1)));
}
}
} else {
this.errorBox.text = "Hex length for " + tmp[i] + " is not an even length";
}
}
} else {
if (sText.length % 2 != 0) {
this.errorBox.text = "Hex String is not an even length!";
return;
} else {
for (j = 0; j < sText.length; j += 2) {
swfBytes.writeByte(int("0x" + sText.charAt(j) + sText.charAt(j+1)));
}
}
}
this.HV.initViewer(this.swfBytes);
HV.updateHexArray();
}
/**
* @private
* This handles the visual aspects of the search and utilizes the HexViewer to perform the search.
*/
private function findHexString():void {
if (hexSearchText.text == null) {
return;
}
var findNext:Boolean = false;
if (this.searchHexButton.label.indexOf("Find Next") == 0) {
findNext = true;
}
this.hvWrapText.setStyle("color", 0xFF0000);
var pos:int = 0;
if (this.hvSearchCB.selectedIndex == 1) { //String
pos = this.HV.findString(this.hexSearchText.text,findNext);
} else {
var re:RegExp = /^[A-Fa-f0-9]+$/g;
if (re.test(this.hexSearchText.text) == false) {
this.hvWrapText.text = 'Invalid Hex Characters';
return;
}
pos = this.HV.findHexString(this.hexSearchText.text,findNext);
}
var cp:CellPosition;
if (pos != -1) {
this.hvDataGrid.selectedIndex = pos;
cp = new CellPosition(pos,this.HV.currentPosition.column);
this.hvDataGrid.selectedCell = cp;
this.hvDataGrid.ensureCellIsVisible(pos);
this.hvWrapText.text = "";
this.searchHexButton.label="Find Next";
} else if (pos == -1 && findNext == true) {
this.hvWrapText.text = 'Search Wrapped';
if (this.hvSearchCB.selectedIndex == 1) { //String
pos = this.HV.findString(this.hexSearchText.text,false);
} else {
pos = this.HV.findHexString(this.hexSearchText.text,false);
}
this.hvDataGrid.selectedIndex = pos;
cp = new CellPosition(pos,this.HV.currentPosition.column);
this.hvDataGrid.selectedCell = cp;
this.hvDataGrid.ensureCellIsVisible(pos);
this.searchHexButton.label="Find Next";
} else if (pos == -1) {
this.hvDataGrid.selectedIndex = -1;
this.searchHexButton.label = "Find";
this.hvWrapText.text = 'Not Found';
}
}
/**
* @private
* Switches the endian-ness in the hex table
*/
private function switchEndian():void {
var i:int = 0;
if (this.swfBytes.length % 4 != 0) {
this.swfBytes.position = this.swfBytes.length -1;
while (i < this.swfBytes.length % 4) {
this.swfBytes.writeByte(0);
i++
}
this.swfBytes.position = 0;
}
for (i = 0; i < this.swfBytes.length; i += 4) {
var tmp:uint;
tmp = this.swfBytes[i];
this.swfBytes[i] = this.swfBytes[i + 3];
this.swfBytes[i + 3] = tmp;
tmp = this.swfBytes[i+2];
this.swfBytes[i+2] = this.swfBytes[i+1];
this.swfBytes[i+1] = tmp;
}
this.HV.initViewer(this.swfBytes);
HV.updateHexArray();
}
/**
* @private
* Load a file directly
*/
private function loadFile():void {
this.swfBytes.clear();
if (this.fActions == null) {
this.fActions = new FileActions();
}
this.fActions.currentFile = File.userDirectory.resolvePath("/");
this.fActions.addEventListener(FileActionEvent.OPEN_RO_COMPLETE, getBytes);
this.fActions.addEventListener(ErrorEvent.ERROR, fileError);
this.fActions.addEventListener(FileActionEvent.IO_ERROR, fileError);
this.fActions.openFile(new FileFilter("Any File", "*.*;"), FileActions.READ);
}
/**
* @private
* Read in all the bytes selected by loadFile
*/
private function getBytes(e:Event):void {
this.fActions.readAllBytes(this.swfBytes);
this.HV.initViewer(this.swfBytes);
HV.updateHexArray();
this.fActions.closeFile();
}
/**
* @private
* Handle any file errors
*/
private function fileError(e:FileActionEvent):void {
mx.controls.Alert.show("Encountered error: " + e.message,"Error",4,this);
}
]]>
</fx:Script>
<s:Label x="16" y="24" text="Source data" width="145"/>
<s:Label x="483" y="15" width="265" id="errorBox" height="31" color="#FE0909"/>
<s:TextArea x="17.95" y="45.2" width="730" height="75" id="sourceText"
toolTip="The 'Copy Hex to Grid' button supports data represented as '0x44445555', '44555544', '44,55' or '0x44,0x55'.
The 'Convert Integers to Hex' button supports data represented as '12345678, 87654321'."/>
<s:Button x="457.45" y="123.65" label="Copy Hex to Grid" click="copyToGrid()"/>
<s:Button x="599.2" y="123.6" label="Convert Integers to Hex" click="convertToHex()"/>
<mx:HRule x="20" y="162" width="723" height="4"/>
<s:Button x="12" y="188" label="Load a File" click="loadFile()"/>
<s:TextInput x="374" y="189" width="180" id="hexSearchText" enabled="true" click="this.searchHexButton.label='Find';this.hvWrapText.text='';"/>
<s:DropDownList x="563.9" y="189.75" id="hvSearchCB" dataProvider="{ this.hvSearchType }" width="96" selectedIndex="0"/>
<s:Button x="667" y="189.25" label="Find" id="searchHexButton" click="findHexString()"/>
<s:Label x="10" y="58" id="hvWrapText" text="" width="184" height="18"/>
<s:DataGrid selectionMode="multipleCells" id="hvDataGrid" x="10" y="220.9" width="728" height="384"
dataProvider="{ this.HV.initDG }" enabled="true" sortableColumns="false" editable="true"
initialize="initializeDG()" gridItemEditorSessionSave="updateString(event)">
<s:columns>
<s:ArrayList>
<s:GridColumn headerText="Offset" dataField="offset" width="75" editable="false" sortable="false"/>
<s:GridColumn headerText="" dataField="space1" width="15" editable="false" sortable="false"/>
<s:GridColumn headerText="0" dataField="col0" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="1" dataField="col1" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="2" dataField="col2" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="3" dataField="col3" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="4" dataField="col4" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="5" dataField="col5" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="6" dataField="col6" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="7" dataField="col7" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="8" dataField="col8" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="9" dataField="col9" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="10" dataField="col10" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="11" dataField="col11" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="12" dataField="col12" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="13" dataField="col13" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="14" dataField="col14" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="15" dataField="col15" width="30" editable="true" sortable="false" itemEditor="hexEditor.HexValidator"/>
<s:GridColumn headerText="" dataField="space2" width="15" editable="false" sortable="false"/>
<s:GridColumn headerText="String" dataField="string" editable="false" sortable="false"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:Button x="24" y="617" label="Switch Endian" width="108" click="switchEndian()"/>
<s:Button x="667.95" y="617" label="Save" id="hvSave" click="this.HV.saveToFile()" />
<s:Button x="140" y="617" label="Compress" width="99" click="compressData()"/>
<s:Button x="246" y="617" label="Uncompress" width="98" click="uncompressData()"/>
<s:TextInput x="448" y="617" id="xorValue" width="90"/>
<s:Button x="543" y="617" label="XOR" click="xorData()" width="46"/>
<s:Label x="380" y="622" text="XOR Value:"/>
</s:Window>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.