Skip to content

Instantly share code, notes, and snippets.

@ienaga
Last active April 28, 2016 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ienaga/2021e8082587b7406ef6 to your computer and use it in GitHub Desktop.
Save ienaga/2021e8082587b7406ef6 to your computer and use it in GitHub Desktop.
swf2jsでswfを直接分解してcanvasに出力する ref: http://qiita.com/ienaga/items/b4412baa95afe882907b
/**
* 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) : [];
};
...省略
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;
}
}
}
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;
}
}
}
/**
* 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