Last active
April 28, 2016 06:32
-
-
Save ienaga/2021e8082587b7406ef6 to your computer and use it in GitHub Desktop.
swf2jsでswfを直接分解してcanvasに出力する ref: http://qiita.com/ienaga/items/b4412baa95afe882907b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* BitIO | |
* @constructor | |
*/ | |
var BitIO = function() | |
{ | |
this.data = null; | |
this.bit_offset = 0; | |
this.byte_offset = 0; | |
this.bit_buffer = null; | |
}; | |
/** | |
* init | |
* @param binary | |
*/ | |
BitIO.prototype.init = function(binary) | |
{ | |
var _this = this; | |
var length = binary.length; | |
var array = _this.createArray(length); | |
var key = 0; | |
for (; length--;) { | |
array[key] = binary.charCodeAt(key++) & 0xff; | |
} | |
this.data = array; | |
}; | |
/** | |
* createArray | |
* @param length | |
* @returns {Array} | |
*/ | |
BitIO.prototype.createArray = function(length) | |
{ | |
return (window.ArrayBuffer) ? new Uint8Array(length) : []; | |
}; | |
...省略 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xmlHttpRequest = new XMLHttpRequest(); | |
xmlHttpRequest.open('GET', url); | |
// XMLHttpRequest2が使えるなら使う | |
isXHR2 = typeof xmlHttpRequest.responseType != 'undefined'; | |
if (isXHR2) { | |
xmlHttpRequest.responseType = 'arraybuffer'; | |
} else { | |
xmlHttpRequest.overrideMimeType( | |
'text/plain; charset=x-user-defined' | |
); | |
} | |
xmlHttpRequest.send(null); | |
xmlHttpRequest.onreadystatechange = function() | |
{ | |
var readyState = xmlHttpRequest.readyState; | |
if (readyState == 4) { | |
var status = xmlHttpRequest.status; | |
switch (status) { | |
case 200: | |
// 分解の実装 | |
parse(isXHR2 ? xmlHttpRequest.response : xmlHttpRequest.responseText, player.parent); | |
...省略 | |
break; | |
case 404: | |
alert('Swf Data Not Found'); | |
break; | |
case 500: | |
alert('Internal Server Error'); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xmlHttpRequest = new XMLHttpRequest(); | |
xmlHttpRequest.open('GET', url); | |
// XMLHttpRequest2が使えるなら使う | |
isXHR2 = typeof xmlHttpRequest.responseType != 'undefined'; | |
if (isXHR2) { | |
xmlHttpRequest.responseType = 'arraybuffer'; | |
} else { | |
xmlHttpRequest.overrideMimeType( | |
'text/plain; charset=x-user-defined' | |
); | |
} | |
xmlHttpRequest.send(null); | |
xmlHttpRequest.onreadystatechange = function() | |
{ | |
var readyState = xmlHttpRequest.readyState; | |
if (readyState == 4) { | |
var status = xmlHttpRequest.status; | |
switch (status) { | |
case 200: | |
// 分解の実装 | |
parse(isXHR2 ? xmlHttpRequest.response : xmlHttpRequest.responseText, player.parent); | |
...省略 | |
break; | |
case 404: | |
alert('Swf Data Not Found'); | |
break; | |
case 500: | |
alert('Internal Server Error'); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* BitIO | |
* @constructor | |
*/ | |
var BitIO = function() | |
{ | |
this.data = null; | |
this.bit_offset = 0; | |
this.byte_offset = 0; | |
this.bit_buffer = null; | |
}; | |
/** | |
* init | |
* @param binary | |
*/ | |
BitIO.prototype.init = function(binary) | |
{ | |
var _this = this; | |
var length = binary.length; | |
var array = _this.createArray(length); | |
var key = 0; | |
for (; length--;) { | |
array[key] = binary.charCodeAt(key++) & 0xff; | |
} | |
this.data = array; | |
}; | |
/** | |
* createArray | |
* @param length | |
* @returns {Array} | |
*/ | |
BitIO.prototype.createArray = function(length) | |
{ | |
return (window.ArrayBuffer) ? new Uint8Array(length) : []; | |
}; | |
...省略 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment