inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Oct 10, 2016 8:14:52 GMT -8
You showed the first few bytes then showed the json data I was just pointing it out for those interested that there was more involved. untagged you. It's great that you are sharing info, but it just seemed like you were correcting me on something I hadn't mentioned, as I was just referring to magic numbers and showing where it starts. Was just confused, that's all.
|
|
Former Member
inherit
guest@proboards.com
225992
0
Nov 27, 2024 12:42:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Oct 10, 2016 8:48:53 GMT -8
Peter No sorry, didn't mean it to sound like I was correcting you. You are right, I was simply pointing out the data is actually starting at byte 16 is all. So to get to the data you would do something like this.(no error checking or file types validation done) 'use strict'
const fs = require('fs') const zlib = require('zlib')
const FILE_HEADER_SIZE = 16
// // --------------------------------------------------- const parseFile = function(file){ let fileStats = fs.statSync(file)
fs.open(file, 'r', (err, fd)=>{ if(err) return const buffer = new Buffer(fileStats['size'])
fs.read(fd, buffer,0, fileStats['size'], null, (err, bytesRead, buffer)=>{ if(err) return readBuffer(buffer, bytesRead) })
fs.closeSync(fd) }) } // // --------------------------------------------------- const readBuffer = function(buffer, bytesRead){ let uncompressedDataSize = buffer.readInt32LE(buffer.length-4, 4)
zlib.inflateRaw(buffer.slice(FILE_HEADER_SIZE, buffer.length-4), (err, data)=>{ if( uncompressedDataSize === data.length ){ console.dir( JSON.parse(data) ) } }) } // // ---------------------------------------------------- parseFile(process.argv[2])
node index.js pluginname.pbp
|
|
Former Member
inherit
guest@proboards.com
225992
0
Nov 27, 2024 12:42:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Oct 10, 2016 10:58:03 GMT -8
Is this something you guys might be interested in? This is a rough sketch of what I'm thinking for a Command Line(CLI) tool for nodejs, let me know what you guys think or if your interested in getting involved The feature list I have so far is - Parser
- Components(css|js) Builder
- Page Builder
- Meta Data
- Settings(page)
[Any plugin that is not editable won't be parsed]
|
|
Former Member
inherit
guest@proboards.com
225992
0
Nov 27, 2024 12:42:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Oct 10, 2016 18:10:40 GMT -8
I created a repo and just have a little boilerplate stuff up at the moment, so If anyone wants to fork it and or contribute, head over to github.com/philip82/PBPluginFactoryYou will need nodeV6 at least installed for Es6 support Ignore the README.md, again just some boilerplate stuff
|
|
inherit
168679
0
Nov 18, 2012 17:03:07 GMT -8
Virgil Sovereign
Latet anguis in herba.
686
July 2011
syonidv
|
Post by Virgil Sovereign on Oct 13, 2016 9:10:42 GMT -8
I created a repo and just have a little boilerplate stuff up at the moment, so If anyone wants to fork it and or contribute, head over to github.com/philip82/PBPluginFactoryYou will need nodeV6 at least installed for Es6 support Ignore the README.md, again just some boilerplate stuff I wish I had the time. It looks like it's going to be a great tool.
|
|
Former Member
inherit
guest@proboards.com
225992
0
Nov 27, 2024 12:42:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Oct 13, 2016 15:24:41 GMT -8
Cheers and no worries Virgil Sovereign Feel free to contribute by offering suggestions.
|
|
Former Member
inherit
guest@proboards.com
225992
0
Nov 27, 2024 12:42:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Nov 9, 2016 15:21:41 GMT -8
This tool is almost done. I've not updated the github account with the refactors just yet as testing is a bit of a pain(I only publish when tests pass, which they do) but not had the time to check since I refactored. This is a side project so If anyone else wants to get it involved it might speed up the process. Also I only have about 80% understanding of the validation rules on the settings_ui(pages), ie: input,textbox The parser is done and tested, maybe the staff might want to jump in on this and provide support for PBP2? VS Admin, Tim Camara ? 'use strict'
const FS = require('fs') const Zlib = require('zlib')
class Parser { constructor(){ this.header = null; this.footer = null; this.compressedData = null; this.headerSize = 16; } /** * Parse * @param string plugin * @return Promise **/ parse(plugin){ return new Promise((resolve, reject) => { FS.open(plugin, 'r', (err, fileDescriptor) => { if(err) return reject(new Error(err));
let fileSize = FS.statSync(plugin); let buffer = new Buffer(fileSize['size']);
FS.readFile(fileDescriptor, buffer, 0, fileSize['size'], null, (err, buffer) => { if(err) return reject(new Error(err));
return resolve(buffer); }); }); }); } /** * Buffer * @param Uint8Array buffer * @return Promise **/ buffer(buffer){ return new Promise((resolve, reject) => {
if(!(buffer instanceof Uint8Array)){ return reject( new Error('the parameter supplied is not valid Uint8Array') ) }
this.header = buffer.slice(0, this.headerSize); this.compressedData = buffer.slice(this.headerSize, buffer.length-4); this.footer = buffer.readInt32LE(buffer.length-4, 4);
return resolve(this.compressedData); }); } /** * Uncompress * @param Utf8Array buffer * @return Promise **/ uncompress(compressed){ return new Promise((resolve, reject) => {
if(!(compressed instanceof Uint8Array)){ return reject(new Error('the parameter supplied is not valid Uint8Array')) }
Zlib.inflateRaw(compressed, (err, decompressed)=>{ if(err) return reject(new Error(err));
let data = JSON.parse(decompressed);
if(decompressed.length === this.footer && data.editable === 1) return resolve(data); });
}); } /** * output * @param Object data * @param string output * @return Promise **/ output(data, output){ return new Promise((resolve, reject) => {
if(Object.prototype.toString.call(data) !== '[object Object]') return reject(new Error('data parameter needs to be a valid [object Object]'));
let file = output + '.json';
FS.writeFile(file, JSON.stringify(data, null, 2), (err)=>{ if(err) return reject(new Error(err));
return resolve(true); });
}); } }
module.exports = Parser module.exports = Object.freeze({ COMPRESSION : { 0 : 'RESERVED', 8 : 'DEFLATE' }, OS : { 0 : 'WIN', 2 : 'VMS', 3 : 'UNIX', 4 : 'VM', 6 : 'HPFS', 7 : 'MAC', 255 : 'UNKNOWN' }, FLAGS : { GZIP : { FTEXT : 0x01, // treat as text instead of binary FHCRC : 0x02, // checksum flag FEXTRA : 0x04, // extra fields flag FNAME : 0x08, // original name FCOMMENT : 0x10, // contains comments RESERVED1 : 0x20, // must be set to zero RESERVED2 : 0x40, // must be set to zero RESERVED3 : 0x80 // must be set to zero }, COMPRESSION : { SLOW : 0x02, //slowest compression FAST : 0x04 //fastest compression } } }) #!/usr/bin/env node
'use strict'
const Commander = require('commander') const Color = require('colors') const Path = require('path') const Package = require('../package.json') const Parser = require('../PBPluginFactory/Parser') /** * * **/ Commander.version(Package.version) /** * * **/ Commander.command('parse <plugin> <output>').action((plugin, output) =>{ let parser = new Parser; let pluginPath = Path.resolve(plugin); let outputPath = (!output || output === 'null') ? Path.resolve('./test.json') : Path.resolve(output);
parser.parse(pluginPath) .then(response => { console.log(Color.green("Parsing plugin ", pluginPath)) console.log(Color.green("Reading plugin ... ")); return parser.buffer(response); }) .then(buffered => { console.log(Color.green("Reading buffer ...")) return parser.uncompress(buffered); }) .then(decompressed => { console.log(Color.green("decompressing buffer ...")); return parser.output(decompressed, outputPath); }) .then(exported => { console.log(Color.green("exporting result to", outputPath)); console.log(parser); }) .catch( err => console.log(Color.red(err.message))) }) /** * * **/ Commander.parse(process.argv)
|
|
inherit
The Dream Crusher (Ret.)
164921
0
Apr 1, 2014 11:00:25 GMT -8
Tim Camara
Teach a man to fish, etc., etc.
1,721
March 2011
tcamara
|
Post by Tim Camara on Nov 9, 2016 16:42:48 GMT -8
The parser is done and tested, maybe the staff might want to jump in on this and provide support for PBP2? VS Admin , Tim Camara ? There isn't a PBP2 at this time. Just PBP0 and PBP1. PBP0 was the initial version that, iirc, didn't use gzip. Plugins can't be saved in PBP0 anymore, so that's just a backwards compatibility thing at this point. V6 could conceivably introduce a PBP2 format, but I can't comment on the likelihood of that at this time.
|
|
Former Member
inherit
guest@proboards.com
225992
0
Nov 27, 2024 12:42:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Nov 9, 2016 17:28:05 GMT -8
Thanks Tim Camara, Is this something you guys could provide support for down the line? As you can see from the code, nothing malicious going on, just a plugin tool to provide boilerplate code for the more mundane tasks.
|
|
inherit
The Dream Crusher (Ret.)
164921
0
Apr 1, 2014 11:00:25 GMT -8
Tim Camara
Teach a man to fish, etc., etc.
1,721
March 2011
tcamara
|
Post by Tim Camara on Nov 10, 2016 11:28:18 GMT -8
Supporting it in an official capacity is unlikely. We'd rather devote the time to the plugin tools that are in the admin areas themselves, to provide a better plugin authoring experience for all users without needing to leave their forum. That being said, we have no problem with a tool like this, and should be happy to answer questions as they arise.
|
|