Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const index = sorted.lte(state.addresses, from)
if (index === -1) {
opts.warn(`${event} address ${fromAddr} not found`)
cb()
return
}
const entry = state.code[state.addresses[index]]
const edge = to + entry[SIZE]
sorted.remove(state.addresses, from)
state.code[from] = undefined
// clear out entries in what will be the new address range of the moved entry
var addr = edge - 1
while (addr >= to) {
const ix = sorted.lte(state.addresses, addr)
if (ix === -1) break
const match = state.addresses[ix]
addr = match - 1
// code previously cleared:
if (state.code[match] === undefined) {
sorted.remove(state.addresses, match)
continue
}
if (match + +state.code[match][SIZE] <= to) continue
sorted.remove(state.addresses, match)
state.code[match] = undefined
}
entry[START] = toAddr
state.code[to] = entry
return function (row, cb) {
const [event, fromAddr, toAddr] = row
const from = parseInt(fromAddr, 16)
const to = parseInt(toAddr, 16)
const index = sorted.lte(state.addresses, from)
if (index === -1) {
opts.warn(`${event} address ${fromAddr} not found`)
cb()
return
}
const entry = state.code[state.addresses[index]]
const edge = to + entry[SIZE]
sorted.remove(state.addresses, from)
state.code[from] = undefined
// clear out entries in what will be the new address range of the moved entry
var addr = edge - 1
while (addr >= to) {
const ix = sorted.lte(state.addresses, addr)
if (ix === -1) break
Storage.prototype._get = function (offset) {
if (this._last) { // high chance that we'll hit the same at least twice
if (this._last.start <= offset && this._last.end > offset) return this._last
}
var i = sorted.lte(this.stores, {start: offset}, cmp)
if (i === -1) return null
var next = this.stores[i]
if (next.start <= offset && next.end > offset) {
this._last = next
return next
}
return null
}
Storage.prototype._get = function (offset) {
var i = fns.lte(this._opened, {start: offset}, cmp)
if (i === -1) return null
var file = this._opened[i]
return offset < file.end ? file : null
}
const ix = sorted.lte(state.addresses, extCbOrTos)
if (ix > -1) {
const match = state.code[state.addresses[ix]]
const isJsFunction = match[FUNC] && match.cs
if (isJsFunction) stack.unshift(extCbOrTos)
}
}
for (const i in stack) {
var addr = parseInt(stack[i], 16)
const codeAddr = state.addresses[sorted.lte(state.addresses, addr)]
stack[i] = state.code[codeAddr] || { name: stack[i] }
if (stack[i].type === 'LIB') {
await loadSymbols(stack[i])
const codeAddr = state.addresses[sorted.lte(state.addresses, addr)]
stack[i] = state.code[codeAddr]
}
}
const vm = vmMap(vmState)
cb(null, {
event,
[PC]: pc,
ts,
[IS_EXT_CB]: isExtCb,
[EXT_CB_OR_TOS]: extCbOrTos,
[VM_STATE]: vmState,
vm,
stack: stack.reverse()
})
return async function (row, cb) {
const [
event, pc, ts, isExtCb, extCbOrTos, vmState, ...stack
] = row
if (isExtCb === '1') {
stack.unshift(extCbOrTos)
} else {
stack.unshift(pc)
const ix = sorted.lte(state.addresses, extCbOrTos)
if (ix > -1) {
const match = state.code[state.addresses[ix]]
const isJsFunction = match[FUNC] && match.cs
if (isJsFunction) stack.unshift(extCbOrTos)
}
}
for (const i in stack) {
var addr = parseInt(stack[i], 16)
const codeAddr = state.addresses[sorted.lte(state.addresses, addr)]
stack[i] = state.code[codeAddr] || { name: stack[i] }
if (stack[i].type === 'LIB') {
await loadSymbols(stack[i])
const codeAddr = state.addresses[sorted.lte(state.addresses, addr)]
stack[i] = state.code[codeAddr]