Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Corrode = require('corrode');
const SECTOR_SIZE = 2048;
const ENTRY_SIZE = 32;
Corrode.addExtension('dir', function(){
this
.loop('entries', function(){
this
.uint32('offset')
.uint32('size')
.string('name', 24)
.map.trimNull('name')
.tap(function(){
this.vars.offset *= SECTOR_SIZE;
this.vars.size *= SECTOR_SIZE;
this.emit('entry', this.vars);
});
})
// file-length should match the count of entries
.tap(function(){
const Corrode = require('corrode');
const SECTOR_SIZE = 2048;
const ENTRY_SIZE = 32;
Corrode.addExtension('dir', function(){
this
.loop('entries', function(end, discard, i){
this
.uint32('offset')
.uint32('size')
.string('name', 24)
.map.trimNull('name')
.tap(function(){
this.vars.offset *= SECTOR_SIZE;
this.vars.size *= SECTOR_SIZE;
this.emit('entry', this.vars);
});
})
// file-length should match the count of entries
.tap(function(){
const Corrode = require('corrode');
Corrode.addExtension('img', function(dir, entryName){
if(typeof dir === 'string'){
dir = this.varStack.peek()[dir];
}
const dirEntry = dir[entryName];
if(!dirEntry){
throw new Error(`No entry with name ${entryName} found.`);
}
return this
.skip(dirEntry.offset)
.buffer('buffer', dirEntry.size)
.map.push('buffer');
});
const Corrode = require('corrode');
require('./tkey');
require('./tdat');
Corrode.addExtension('gxt', function(){
this
.ext.gxtTkey('tkey')
.ext.gxtTdat('tdat', 'tkey')
.map.push('tdat');
});