Started the rewrite!!!
This commit is contained in:
parent
29b4371f94
commit
0ada63230d
112
BinRewrite.md
Normal file
112
BinRewrite.md
Normal file
@ -0,0 +1,112 @@
|
||||
# Bin Rewrite Progress!
|
||||
**Note: A lot breaks (Almost everything) for the sake of consistency**
|
||||
Progress: [==- - - - - - - - 10% - - - - - - - - -]
|
||||
### List of new methods
|
||||
- [x] bin.newFromB64(data)
|
||||
- [x] bin.newFromHex(data)
|
||||
- [x] bin:read(n) -- works just like normal read on a file for both stream/bin files
|
||||
- [x] bin:sub(a,b) -- works like string.sub() but for bin objects
|
||||
- [ ] bin:seekSet(n) -- sets the seek position on the file
|
||||
|
||||
### List of converted methods and their status
|
||||
- [ ] log(data,name,fmt)
|
||||
- [ ] bin.getLuaVersion()
|
||||
- [x] ~~bin.load(filename,s,r)~~
|
||||
- [x] ~~bin.new(string data)~~ -- Does not accept b64 or hex data anymore! Use new methods for that ^^^
|
||||
- [ ] bin.stream(file,lock)
|
||||
- [ ] bin.newTempFile(data)
|
||||
- [x] ~~bin:getSize(fmt)~~ -- gets the size of the string fmt is how you want to format it. left empte returns number of bites as a lua number supports lua formats! And also I added the %b format for base64
|
||||
- [ ] bin:getData(fmt) -- returns the data of the object as a string, supports %x(hex), %X(HEX) and %b(base64)
|
||||
- [ ] bits.new(n)
|
||||
- [ ] bin.newVFS()
|
||||
- [x] ~~bin:tackE(data)~~ -- tacks data onto the end of a file
|
||||
- [x] ~~bin:tofile(path)~~
|
||||
- [ ] bin.loadVFS(path)
|
||||
- [ ] bin:newDataBuffer(s)
|
||||
- [ ] bin.bufferToBin(b)
|
||||
- [ ] bin.binToBuffer(b)
|
||||
- [ ] bin:getDataBuffer(a,b)
|
||||
- [ ] bin.newNamedBlock(indexSize)
|
||||
- [ ] bin.newStreamedNamedBlock(indexSize,path)
|
||||
- [ ] bin.loadNamedBlock(path)
|
||||
- [ ] bin.namedBlockManager(arg)
|
||||
- [ ] bin.randomName(n,ext)
|
||||
- [ ] bin.NumtoHEX(n)
|
||||
- [ ] bin.HEXtoBin(s)
|
||||
- [ ] bin.HEXtoStr(s)
|
||||
- [x] ~~bin.tohex(s)~~
|
||||
- [x] ~~bin.fromhex(s)~~
|
||||
- [ ] bin.endianflop(data)
|
||||
- [ ] bin.getVersion()
|
||||
- [ ] bin.escapeStr(str)
|
||||
- [ ] bin.ToStr(tab)
|
||||
- [ ] bin.packLLIB(name,tab,ext)
|
||||
- [ ] bin.unpackLLIB(name,exe,todir,over,ext)
|
||||
- [ ] bin.fileExist(path)
|
||||
- [ ] bin.closeto(a,b,v)
|
||||
- [ ] bin.textToBinary(txt)
|
||||
- [ ] bin.decodeBits(bindata)
|
||||
- [ ] bin.trimNul(s)
|
||||
- [ ] bin.getIndexSize(tab)
|
||||
- [ ] bits.numToBytes(num,occ)
|
||||
- [ ] binobj:tofile(filename)
|
||||
- [ ] binobj:clone()
|
||||
- [ ] binobj:compare(other binobj,diff)
|
||||
- [ ] binobj:sub(a,b)
|
||||
- [ ] binobj:tonumber(a,b)
|
||||
- [ ] binobj:getbyte(n)
|
||||
- [ ] binobj:tobits(i)
|
||||
- [ ] binobj:getHEX(a,b)
|
||||
- [ ] binobj:scan(s,n,f)
|
||||
- [ ] binobj:streamData(a,b)
|
||||
- [ ] binobj:streamread(a,b)
|
||||
- [ ] binobj:canStreamWrite()
|
||||
- [ ] bitobj:conv(n)
|
||||
- [ ] bitobj:tobytes()
|
||||
- [ ] bitobj:tonumber()
|
||||
- [ ] bitobj:isover()
|
||||
- [ ] bitobj:getBin()
|
||||
- [ ] binobj:getHash(n)
|
||||
- [ ] binobj:getData()
|
||||
- [ ] blockReader:getBlock(name)
|
||||
- [ ] binobj:setEndOfFile(n)
|
||||
- [ ] binobj:reverse()
|
||||
- [ ] binobj:flipbits()
|
||||
- [ ] binobj:segment(a,b)
|
||||
- [ ] binobj:insert(a,i)
|
||||
- [ ] binobj:parseN(n)
|
||||
- [ ] binobj:getlength()
|
||||
- [ ] binobj:shift(n)
|
||||
- [ ] binobj:delete(a,b)
|
||||
- [ ] binobj:encrypt(seed)
|
||||
- [ ] binobj:decrypt(seed)
|
||||
- [ ] binobj:shuffle()
|
||||
- [ ] binobj:mutate(a,i)
|
||||
- [ ] binobj:merge(o,t)
|
||||
- [ ] binobj:parseA(n,a,t)
|
||||
- [ ] binobj:getHEX(a,b)
|
||||
- [ ] binobj:cryptM()
|
||||
- [ ] binobj:addBlock(d,n)
|
||||
- [ ] binobj:getBlock(t,n)
|
||||
- [x] ~~binobj:seek(n)~~
|
||||
- [ ] binobj:morph(a,b,d)
|
||||
- [ ] binobj:fill(n,d)
|
||||
- [ ] binobj:fillrandom(n)
|
||||
- [ ] binobj:shiftbits(n)
|
||||
- [ ] binobj:shiftbit(n,i)
|
||||
- [ ] binobj:streamwrite(d,n)
|
||||
- [ ] binobj:open()
|
||||
- [ ] binobj:close()
|
||||
- [ ] binobj:wipe()
|
||||
- [ ] binobj:tackB(d)
|
||||
- [ ] binobj:tackE(d)
|
||||
- [ ] binobj:parse(n,f)
|
||||
- [ ] binobj:flipbit(i)
|
||||
- [ ] binobj:gsub()
|
||||
- [ ] blockWriter:addNamedBlock(name,value)
|
||||
- [ ] bitobj:add(i)
|
||||
- [ ] bitobj:sub(i)
|
||||
- [ ] bitobj:multi(i)
|
||||
- [ ] bitobj:div(i)
|
||||
- [ ] bitobj:flipbits()
|
||||
- [ ] bitobj:getBin()
|
||||
293
rewritedata/bin/init.lua
Normal file
293
rewritedata/bin/init.lua
Normal file
@ -0,0 +1,293 @@
|
||||
-- Well Its finally time for that massive rewrite that has been long awaited for
|
||||
-- We need to keep things thread safe or the rewrite would have been in vain... Also this will ensure that all features are working perfectly
|
||||
bin={}
|
||||
bin.Version={5,0,0}
|
||||
bin.stage='stable'
|
||||
bin.data=''
|
||||
bin.t='bin'
|
||||
bin.__index = bin
|
||||
bin.__tostring=function(self) return self:getData() end
|
||||
bin.__len=function(self) return self:getlength() end
|
||||
bits={}
|
||||
bits.data=''
|
||||
bits.t='bits'
|
||||
bits.__index = bits
|
||||
bits.__tostring=function(self) return self.data end
|
||||
bits.__len=function(self) return (#self.data)/8 end
|
||||
bin.lastBlockSize=0
|
||||
bin.streams={} -- FIX FOR THREADING!!!
|
||||
bin.base64chars = {[0]='A',[1]='B',[2]='C',[3]='D',[4]='E',[5]='F',[6]='G',[7]='H',[8]='I',[9]='J',[10]='K',[11]='L',[12]='M',[13]='N',[14]='O',[15]='P',[16]='Q',[17]='R',[18]='S',[19]='T',[20]='U',[21]='V',[22]='W',[23]='X',[24]='Y',[25]='Z',[26]='a',[27]='b',[28]='c',[29]='d',[30]='e',[31]='f',[32]='g',[33]='h',[34]='i',[35]='j',[36]='k',[37]='l',[38]='m',[39]='n',[40]='o',[41]='p',[42]='q',[43]='r',[44]='s',[45]='t',[46]='u',[47]='v',[48]='w',[49]='x',[50]='y',[51]='z',[52]='0',[53]='1',[54]='2',[55]='3',[56]='4',[57]='5',[58]='6',[59]='7',[60]='8',[61]='9',[62]='-',[63]='_'}
|
||||
-- Helpers
|
||||
function bin.fileExist(path)
|
||||
g=io.open(path or '','r')
|
||||
if path =='' then
|
||||
p='empty path'
|
||||
return nil
|
||||
end
|
||||
if g~=nil and true or false then
|
||||
p=(g~=nil and true or false)
|
||||
end
|
||||
if g~=nil then
|
||||
io.close(g)
|
||||
else
|
||||
return false
|
||||
end
|
||||
return p
|
||||
end
|
||||
function bin.toB64(data)
|
||||
local bytes = {}
|
||||
local result = ""
|
||||
for spos=0,string.len(data)-1,3 do
|
||||
for byte=1,3 do bytes[byte] = string.byte(string.sub(data,(spos+byte))) or 0 end
|
||||
result = string.format('%s%s%s%s%s',result,bin.base64chars[bits.rsh(bytes[1],2)],bin.base64chars[bits.lor(bits.lsh((bytes[1] % 4),4), bits.rsh(bytes[2],4))] or "=",((#data-spos) > 1) and bin.base64chars[bits.lor(bits.lsh(bytes[2] % 16,2), bits.rsh(bytes[3],6))] or "=",((#data-spos) > 2) and bin.base64chars[(bytes[3] % 64)] or "=")
|
||||
end
|
||||
return result
|
||||
end
|
||||
bin.base64bytes = {['A']=0,['B']=1,['C']=2,['D']=3,['E']=4,['F']=5,['G']=6,['H']=7,['I']=8,['J']=9,['K']=10,['L']=11,['M']=12,['N']=13,['O']=14,['P']=15,['Q']=16,['R']=17,['S']=18,['T']=19,['U']=20,['V']=21,['W']=22,['X']=23,['Y']=24,['Z']=25,['a']=26,['b']=27,['c']=28,['d']=29,['e']=30,['f']=31,['g']=32,['h']=33,['i']=34,['j']=35,['k']=36,['l']=37,['m']=38,['n']=39,['o']=40,['p']=41,['q']=42,['r']=43,['s']=44,['t']=45,['u']=46,['v']=47,['w']=48,['x']=49,['y']=50,['z']=51,['0']=52,['1']=53,['2']=54,['3']=55,['4']=56,['5']=57,['6']=58,['7']=59,['8']=60,['9']=61,['-']=62,['_']=63,['=']=nil}
|
||||
function bin.fromB64(data)
|
||||
local chars = {}
|
||||
local result=""
|
||||
for dpos=0,string.len(data)-1,4 do
|
||||
for char=1,4 do chars[char] = bin.base64bytes[(string.sub(data,(dpos+char),(dpos+char)) or "=")] end
|
||||
result = string.format('%s%s%s%s',result,string.char(bits.lor(bits.lsh(chars[1],2), bits.rsh(chars[2],4))),(chars[3] ~= nil) and string.char(bits.lor(bits.lsh(chars[2],4), bits.rsh(chars[3],2))) or "",(chars[4] ~= nil) and string.char(bits.lor(bits.lsh(chars[3],6) % 192, (chars[4]))) or "")
|
||||
end
|
||||
return result
|
||||
end
|
||||
function bin.toHex(str)
|
||||
return (str:gsub('.', function (c)
|
||||
return string.format('%02X', string.byte(c))
|
||||
end))
|
||||
end
|
||||
function bin.fromHex(str)
|
||||
return (str:gsub('..', function (cc)
|
||||
return string.char(tonumber(cc, 16))
|
||||
end))
|
||||
end
|
||||
-- Constructors
|
||||
function bin.new(data)
|
||||
data=tostring(data or "")
|
||||
local c = {}
|
||||
setmetatable(c, bin)
|
||||
c.data=data
|
||||
c.Type="bin"
|
||||
c.t="bin"
|
||||
c.pos=1
|
||||
c.stream=false
|
||||
return c
|
||||
end
|
||||
function bin.newFromB64(data)
|
||||
return bin.new(bin.fromB64(data))
|
||||
end
|
||||
function bin.newFromHex(data)
|
||||
return bin.new(bin.fromHex(data))
|
||||
end
|
||||
function bin.load(path)
|
||||
if type(path) ~= "string" then error("Path must be a string!") end
|
||||
local f = io.open(path, 'rb')
|
||||
local content = f:read('*a')
|
||||
f:close()
|
||||
return bin.new(content)
|
||||
end
|
||||
function bin.stream(file,l)
|
||||
if not(l==false) then l=true end
|
||||
local c=bin.new()
|
||||
c.Type="streamable"
|
||||
c.t="streamable"
|
||||
if bin.streams[file]~=nil then -- FIX FOR THREADING!!!
|
||||
c.file=file
|
||||
c.lock = l
|
||||
c.workingfile=bin.streams[file].workingfile
|
||||
c.stream=true
|
||||
return c
|
||||
end
|
||||
if bin.fileExist(file) then
|
||||
c.file=file
|
||||
c.lock = l
|
||||
c.workingfile=io.open(file,'rb+')
|
||||
else
|
||||
c.file=file
|
||||
c.lock = l
|
||||
c.workingfile=io.open(file,'w')
|
||||
io.close(c.workingfile)
|
||||
c.workingfile=io.open(file,'rb+')
|
||||
end
|
||||
c.stream=true
|
||||
bin.streams[file]=c -- FIX FOR THREADING!!!
|
||||
return c
|
||||
end
|
||||
function bin.freshStream(file)
|
||||
bin.new():tofile(file)
|
||||
return bin.stream(file,false)
|
||||
end
|
||||
function bin.normalizeData(data)
|
||||
if type(data)=="string" then return data end
|
||||
if type(data)=="table" then
|
||||
if data.Type=="bin" or data.Type=="streamable" then
|
||||
return data:getData()
|
||||
elseif data.Type=="bits" then
|
||||
-- LATER
|
||||
elseif data.Type=="buffer" then
|
||||
-- LATER
|
||||
elseif data.Type=="sink" then
|
||||
-- LATER
|
||||
else
|
||||
error("I do not know how to handle this data!")
|
||||
end
|
||||
elseif type(data)=="userdata" then
|
||||
if tostring(data):sub(1,4)=="file" then
|
||||
local cur=data:seek("cur")
|
||||
data:seek("set",0)
|
||||
local dat=data:read("*a")
|
||||
data:seek("set",cur)
|
||||
return dat
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Core Methods
|
||||
function bin:canStreamWrite()
|
||||
return (self.stream and not(self.lock))
|
||||
end
|
||||
function bin:seekSet(n)
|
||||
if self.stream then
|
||||
self.workingfile:seek("set",n-1)
|
||||
else
|
||||
self.pos=n
|
||||
end
|
||||
end
|
||||
function bin:seek(n)
|
||||
if self.stream then
|
||||
if not n then return self.workingfile:seek("cur") end
|
||||
local cur=self.workingfile:seek("cur")
|
||||
self.workingfile:seek("set",cur+n)
|
||||
else
|
||||
if not n then return self.pos end
|
||||
if #self.data-(self.pos-1)<n then
|
||||
print(n-((#self.data)-(self.pos-1)))
|
||||
self:write(string.rep("\0",n-((#self.data)-(self.pos-1))))
|
||||
return
|
||||
end
|
||||
self.pos=self.pos+n
|
||||
end
|
||||
end
|
||||
function bin:read(n)
|
||||
if self.stream then
|
||||
return self.workingfile:read(n)
|
||||
else
|
||||
local data=self.data:sub(self.pos,self.pos+n-1)
|
||||
self.pos=self.pos+n
|
||||
return data
|
||||
end
|
||||
end
|
||||
function bin:write(data,size)
|
||||
local data=bin.normalizeData(data)
|
||||
local dsize=#data
|
||||
local size=tonumber(size or dsize)
|
||||
if dsize>size then
|
||||
data = data:sub(1,size)
|
||||
end
|
||||
if self:canStreamWrite() then
|
||||
self.workingfile:write(data)
|
||||
elseif self.Type=="bin" then
|
||||
local tab={}
|
||||
if self.pos==1 then
|
||||
tab={data,self.data:sub(self.pos+size)}
|
||||
else
|
||||
tab={self.data:sub(1,self.pos-1),data,self.data:sub(self.pos+size)}
|
||||
end
|
||||
self.pos=self.pos+size
|
||||
self.data=table.concat(tab)
|
||||
else
|
||||
error("Attempted to write to a locked file!")
|
||||
end
|
||||
end
|
||||
function bin:sub(a,b)
|
||||
local data=""
|
||||
if self.stream then
|
||||
local cur=self.workingfile:seek("cur")
|
||||
self.workingfile:seek("set",a-1)
|
||||
data=self.workingfile:read(b-(a-1))
|
||||
self.workingfile:seek("set",cur)
|
||||
else
|
||||
data=self.data:sub(a,b)
|
||||
end
|
||||
return data
|
||||
end
|
||||
function bin:getData(fmt)
|
||||
local data=""
|
||||
if self.stream then
|
||||
local cur=self.workingfile:seek("cur")
|
||||
self.workingfile:seek("set",0)
|
||||
data=self.workingfile:read("*a")
|
||||
self.workingfile:seek("set",cur)
|
||||
else
|
||||
data=self.data
|
||||
end
|
||||
if fmt=="%x" or fmt=="hex" then
|
||||
return bin.toHex(data):lower()
|
||||
elseif fmt=="%X" or fmt=="HEX" then
|
||||
return bin.toHex(data)
|
||||
elseif fmt=="%b" or fmt=="b64" then
|
||||
return bin.toB64(data)
|
||||
end
|
||||
return data
|
||||
end
|
||||
function bin:getSize(fmt)
|
||||
local len=0
|
||||
if self.stream then
|
||||
local cur=self.workingfile:seek("cur")
|
||||
len=self.workingfile:seek("end")
|
||||
self.workingfile:seek("set",cur)
|
||||
else
|
||||
len=#self.data
|
||||
end
|
||||
if fmt=="%b" then
|
||||
--return bin.toB64() -- LATER
|
||||
elseif fmt then
|
||||
return string.format(fmt, len)
|
||||
else
|
||||
return len
|
||||
end
|
||||
end
|
||||
function bin:tackE(data,size)
|
||||
local data=bin.normalizeData(data)
|
||||
self:seekSet(self:getSize()+1)
|
||||
self:write(data,size)
|
||||
end
|
||||
function bin:tofile(name)
|
||||
if self.stream then return end
|
||||
if not name then error("Must include a filename to save as!") end
|
||||
file = io.open(name, "wb")
|
||||
file:write(self.data)
|
||||
file:close()
|
||||
end
|
||||
-- Tests
|
||||
test=bin.freshStream("../test.dat",false) -- you must stream unlocked to be able to write to it
|
||||
test2=bin.load("../test.dat")
|
||||
test3=bin.new()
|
||||
print("From Stream\n-----------")
|
||||
test:seek(2)
|
||||
test:write("Like Food",4)
|
||||
test:write("!!",2)
|
||||
test:seek(10)
|
||||
test:write("Hmmmmmm")
|
||||
test:tackE("THE END YO!!!")
|
||||
test:write("@")
|
||||
print(test)
|
||||
print("\nFrom Virtual File\n-----------------")
|
||||
test2:seek(2)
|
||||
test2:write("Like Food",4)
|
||||
test2:write("!!",2)
|
||||
test2:seek(10)
|
||||
test2:write("Hmmmmmm")
|
||||
test2:tackE("THE END YO!!!")
|
||||
test2:write("@")
|
||||
print(test2)
|
||||
print("\nFrom Virtual File2\n-----------------")
|
||||
test3:seek(2)
|
||||
test3:write("Like Food",4)
|
||||
test3:write("!!",2)
|
||||
test3:seek(10)
|
||||
test3:write("Hmmmmmm")
|
||||
test3:tackE("THE END YO!!!")
|
||||
test3:write("@")
|
||||
print(test3)
|
||||
0
rewritedata/bin/vfs.lua
Normal file
0
rewritedata/bin/vfs.lua
Normal file
0
rewritedata/read.dat
Normal file
0
rewritedata/read.dat
Normal file
123
rewritedata/read.txt
Normal file
123
rewritedata/read.txt
Normal file
@ -0,0 +1,123 @@
|
||||
nil = log(data,name,fmt) -- data is the text that you want to log to a file, the name argument only needs to be called with the first log. It tells where to log to. If name is used again it will change the location of the log file.
|
||||
string,string,string = bin.getLuaVersion() -- returns PUC/JIT,major,minor
|
||||
|
||||
Constructors
|
||||
------------
|
||||
binobj = bin.load(filename,s,r) -- creates binobj from file in s and r nil then reads entire file but if not s is the start point of reading and r is either the #to read after s or from s to '#' (like string.sub())
|
||||
binobj = bin.new(string data) -- creates binobj from a string
|
||||
binobj = bin.stream(file,lock) -- creates a streamable binobj lock is defult to true if locked file is read only
|
||||
binobj = bin.newTempFile(data) -- creates a tempfile in stream mode
|
||||
bitobj = bits.new(n) -- creates bitobj from a number
|
||||
vfs = bin.newVFS() -- creates a new virtual file system --Beta
|
||||
vfs = bin.loadVFS(path) -- loads a saved .lvfs file --Beta
|
||||
buf = bin:newDataBuffer(s) -- creates a databuffer
|
||||
binobj = bin.bufferToBin(b) -- converts a buffer object to a bin object
|
||||
buf = bin.binToBuffer(b) -- converts a bin object to a buffer obj
|
||||
buf = bin:getDataBuffer(a,b) -- gets a speical buffer that opperates on a streamed file. It works just like a regular data buffer
|
||||
blockWriter = bin.newNamedBlock(indexSize) -- returns a block writer object index size is the size of the index where labels and pointers are stored
|
||||
blockWriter = bin.newStreamedNamedBlock(indexSize,path) -- returns a streamed version of the above path is the path to write the file
|
||||
blockReader = bin.loadNamedBlock(path) -- returns a block reader object, path is where the file is located
|
||||
blockHandler= bin.namedBlockManager(arg) -- returns a block handler object, if arg is a string it will loade a named block file, if its a number or nil it will create a nambed block object
|
||||
|
||||
Note: the blockWriter that isn't streamed needs to have tofile(path) called on it to write it to a file
|
||||
Note: the streamed blockWriter must have the close method used when you are done writing to it!
|
||||
|
||||
Helpers
|
||||
-------
|
||||
string = bin.randomName(n,ext) -- creates a random file name if n and ext is nil then a random length is used, and '.tmp' extension is added
|
||||
string = bin.NumtoHEX(n) -- turns number into hex
|
||||
binobj = bin.HEXtoBin(s)*D -- turns hex data into binobj
|
||||
string = bin.HEXtoStr(s)*D -- turns hex data into string/text
|
||||
string = bin.tohex(s) -- turns string to hex
|
||||
string = bin.fromhex(s) -- turns hex to string
|
||||
string = bin.endianflop(data) -- flips the high order bits to the low order bits and viseversa
|
||||
string = bin.getVersion() -- returns the version as a string
|
||||
string = bin.escapeStr(str) -- system function that turns functions into easy light
|
||||
string = bin.ToStr(tab) -- turns a table into a string (even functions are dumped; used to create compact data files)
|
||||
nil = bin.packLLIB(name,tab,ext) -- turns a bunch of 'files' into 1 file tab is a table of file names, ext is extension if nil .llib is used Note: Currently does not support directories within .llib
|
||||
nil = bin.unpackLLIB(name,exe,todir,over,ext) -- takes that file and makes the files Note: if exe is true and a .lua file is in the .llib archive than it is ran after extraction ext is extension if nil .llib is used
|
||||
boolean = bin.fileExist(path) -- returns true if the file exist false otherwise
|
||||
boolean*= bin.closeto(a,b,v) -- test data to see how close it is (a,b=tested data v=#difference (v must be <=255))
|
||||
String = bin.textToBinary(txt) -- turns text into binary data 10101010's
|
||||
binobj = bin.decodeBits(bindata) -- turns binary data into text
|
||||
string = bin.trimNul(s) -- terminates string at the nul char
|
||||
number = bin.getIndexSize(tab) -- used to get the index size of labels given to a named block
|
||||
string = bits.numToBytes(num,occ) -- returns the number in base256 string data, occ is the space the number will take up
|
||||
|
||||
Assessors
|
||||
---------
|
||||
nil*** = binobj:tofile(filename) -- writes binobj data as a file
|
||||
binobj* = binobj:clone() -- clones and returns a binobj
|
||||
number* = binobj:compare(other binobj,diff) -- returns 0-100 % of simularity based on diff factor (diff must be <=255)
|
||||
string = binobj:sub(a,b) -- returns string data like segment but dosen't alter the binobject
|
||||
num,num = binobj:tonumber(a,b) -- converts from a-b (if a and b are nil it uses the entire binobj) into a base 10 number so 'AXG' in data becomes 4675649 returns big,little endian
|
||||
number = binobj:getbyte(n) -- gets byte at location and converts to base 10 number
|
||||
bitobj = binobj:tobits(i) -- returns the 8bits of data as a bitobj Ex: if value of byte was a 5 it returns a bitobj with a value of: '00000101'
|
||||
string = binobj:getHEX(a,b) -- gets the HEX data from 'a' to 'b' if both a,b are nil returns entire file as hex
|
||||
a,b = binobj:scan(s,n,f) -- searches a binobj for 's'; n is where to start looking, 'f' is weather or not to flip the string data entered 's'
|
||||
string = binobj:streamData(a,b) -- reads data from a to b or a can be a data handle... I will explain this and more in offical documentation
|
||||
string# = binobj:streamread(a,b) -- reads data from a stream object between a and b (note: while other functions start at 1 for both stream and non stream 0 is the starting point for this one)
|
||||
boolean = binobj:canStreamWrite() -- returns true if the binobj is streamable and isn't locked
|
||||
string = bitobj:conv(n) -- converts number to binary bits (system used)
|
||||
binobj = bitobj:tobytes() -- converts bit obj into a string byte (0-255)
|
||||
number = bitobj:tonumber() -- converts '10101010' to a number
|
||||
boolean = bitobj:isover() -- returns true if the bits exceed 8 bits false if 8 or less
|
||||
string = bitobj:getBin() -- returns the binary 10100100's of the data as a string
|
||||
string = binobj:getHash(n) -- returns a Hash of a file (This is my own method of hashing btw) n is the length you want the hash to be
|
||||
string = binobj:getData() -- returns the bin object as a string
|
||||
depends = blockReader:getBlock(name) -- returns the value associated with the name, values can be any lua data except userdata
|
||||
|
||||
Mutators (Changes affect the actual object or if streaming the actual file) bin:remove()
|
||||
--------
|
||||
nil = binobj:setEndOfFile(n) -- sets the end of a file
|
||||
nil = binobj:reverse() -- reverses binobj data ex: hello --> olleh
|
||||
nil = binobj:flipbits() -- flips the binary bits
|
||||
nil** = binobj:segment(a,b) -- gets a segment of the binobj data works just like string.sub(a,b) without str
|
||||
nil* = binobj:insert(a,i) -- inserts i (string or number(converts into string)) in position a
|
||||
nil* = binobj:parseN(n) -- removes ever (nth) byte of data
|
||||
nil = binobj:getlength() -- gets length or size of binary data
|
||||
nil* = binobj:shift(n) -- shift the binary data by n positive --> negitive <--
|
||||
nil* = binobj:delete(a,b) -- deletes part of a binobj data Usage: binobj:delete(#) deletes at pos # binobj:delete(#1,#2) deletes from #1 to #2 binobj:delete('string') deletes all instances of 'byte' as a string Use string.char(#) or '\#' to get byte as a string
|
||||
nil* = binobj:encrypt(seed) -- encrypts data using a seed, seed may be left blank
|
||||
nil* = binobj:decrypt(seed) -- decrypts data encrypted with encrypt(seed)
|
||||
nil* = binobj:shuffle() -- Shuffles the data randomly Note: there is no way to get it back!!! If original is needed clone beforehand
|
||||
nil** = binobj:mutate(a,i) -- changes position a's value to i
|
||||
nil = binobj:merge(o,t) -- o is the binobj you are merging if t is true it merges the new data to the left of the binobj EX: b:merge(o,true) b='yo' o='data' output: b='datayo' b:merge(o) b='yo' o='data' output: b='yodata'
|
||||
nil* = binobj:parseA(n,a,t) -- n is every byte where you add, a is the data you are adding, t is true or false true before false after
|
||||
nil = binobj:getHEX(a,b) -- returns the HEX of the bytes between a,b inclusive
|
||||
nil = binobj:cryptM() -- a mirrorable encryptor/decryptor
|
||||
nil = binobj:addBlock(d,n) -- adds a block of data to a binobj s is size d is data e is a bool if true then encrypts string values. if data is larger than 'n' then data is lost. n is the size of bytes the data is Note: n is no longer needed but you must use getBlock(type) to get it back
|
||||
nil = binobj:getBlock(t,n) -- gets block of code by type
|
||||
nil = binobj:seek(n) -- used with getBlock EX below with all 3
|
||||
nil* = binobj:morph(a,b,d) -- changes data between point a and b, inclusive, to d
|
||||
nil = binobj:fill(n,d) -- fills binobj with data 'd' for n
|
||||
nil = binobj:fillrandom(n) -- fills binobj with random data for n
|
||||
nil = binobj:shiftbits(n) -- shifts all bits by n amount
|
||||
nil = binobj:shiftbit(n,i) -- shifts a bit ai index i by n
|
||||
nil# = binobj:streamwrite(d,n) -- writes to the streamable binobj d data n position
|
||||
nil# = binobj:open() -- opens the streamable binobj
|
||||
nil# = binobj:close() -- closes the streamable binobj
|
||||
nil = binobj:wipe() -- erases all data in the file
|
||||
nil* = binobj:tackB(d) -- adds data to the beginning of a file
|
||||
nil = binobj:tackE(d) -- adds data to the end of a file
|
||||
nil = binobj:parse(n,f) -- loops through each byte calling function 'f' with the args(i,binobj,data at i)
|
||||
nil = binobj:flipbit(i) -- flips the binary bit at position i
|
||||
nil* = binobj:gsub() -- just like string:gsub(), but mutates self
|
||||
nil = blockWriter:addNamedBlock(name,value) -- writes a named block to the file with name 'name' and the value 'value'
|
||||
|
||||
Note: numbers are written in Big-endian use bin.endianflop(d) to filp to Little-endian
|
||||
|
||||
Note: binobj:tonumber() returns big,little endian so if printing do: b,l=binobj:tonumber() print(l) print(b)
|
||||
|
||||
nil = bitobj:add(i) -- adds i to the bitobj i can be a number (base 10) or a bitobj
|
||||
nil = bitobj:sub(i) -- subs i to the bitobj i can be a number (base 10) or a bitobj
|
||||
nil = bitobj:multi(i) -- multiplys i to the bitobj i can be a number (base 10) or a bitobj
|
||||
nil = bitobj:div(i) -- divides i to the bitobj i can be a number (base 10) or a bitobj
|
||||
nil = bitobj:flipbits() -- filps the bits 1 --> 0, 0 --> 1
|
||||
string = bitobj:getBin() -- returns 1's & 0's of the bitobj
|
||||
|
||||
# stream objects only
|
||||
* not compatible with stream files
|
||||
** works but do not use with large files or it works to some degree
|
||||
*** in stream objects all changes are made directly to the file, so there is no need to do tofile()
|
||||
*D
|
||||
BIN
rewritedata/test.dat
Normal file
BIN
rewritedata/test.dat
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user