Added dir, throwing exceptions n shit, what

git-svn-id: file:///home/svn/incoming/trunk@2335 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Spoon M 2005-04-03 23:13:16 +00:00
parent c5a1fe6716
commit e5a792484c
5 changed files with 59 additions and 96 deletions

18
lib/rex/post/dir.rb Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/ruby
module Rex
module Post
class Dir
def Dir.entries(name)
throw NotImplementedError
end
def Dir.foreach(name, &block)
entries(name).each(&block)
end
end
end; end # Post/Rex

View File

@ -3,6 +3,7 @@
require 'Rex/Post/DispatchNinja/File'
require 'Rex/Post/DispatchNinja/FileStat'
require 'Rex/Post/DispatchNinja/Process'
require 'Rex/Post/DispatchNinja/Dir'
module Rex
module Post
@ -20,22 +21,23 @@ class Client
checksig()
end
def file
klass = Rex::Post::DispatchNinja::File.dup
def brand(klass)
klass = klass.dup
klass.client = self
return klass
end
def filestat
klass = Rex::Post::DispatchNinja::FileStat.dup
klass.client = self
return klass
def file
brand(Rex::Post::DispatchNinja::File)
end
def filestat
brand(Rex::Post::DispatchNinja::FileStat)
end
def process
klass = Rex::Post::DispatchNinja::Process.dup
klass.client = self
return klass
brand(Rex::Post::DispatchNinja::Process)
end
def dir
brand(Rex::Post::DispatchNinja::Dir)
end
def sendmodule(name)

View File

@ -1,117 +1,42 @@
#!/usr/bin/ruby
require 'Rex/DispatchNinja/Stat'
require 'Rex/Post/Dir'
module Rex
module Post
module DispatchNinja
class File < Rex::Post::File
class Dir < Rex::Post::Dir
#
# Class Methods
#
@@structstat = [
'st_dev', 2,
'pad1', 2,
'st_ino', 4,
'st_mode', 2,
'st_nlink', 2,
'st_uid', 2,
'st_gid', 2,
'st_rdev', 2,
'pad2', 2,
'st_size', 4,
'st_blksize', 4,
'st_blocks', 4,
'st_atime', 4,
'unused1', 4,
'st_mtime', 4,
'unused2', 4,
'st_ctime', 4,
'unused3', 4,
'unused4', 4,
'unused5', 4
]
# setup a class variable for our client pointer
class <<self
attr_accessor :client
end
def File.stat(file)
return client.filestat.new(file)
end
def ls(dir)
def Dir.entries(name)
sendmodule('ls')
client.sendmodule('ls')
sendfilename(dir)
client.sendfilename(name)
res = sockread(4).unpack('l')[0] # ug, not portable, later...
res = client.sockread(4).unpack('l')[0] # ug, not portable, later...
files = [ ]
while true
len = sockread(2).unpack('S')[0]
len = client.sockread(2).unpack('S')[0]
break if len == 0
files << sockread(len)
files << client.sockread(len)
end
checksig()
return [ res, files ]
end
def File.stat_hash(file)
client.sendmodule('stat')
client.sendfilename(file)
data = client.sockread(68)
res = data[0, 4].unpack('l')[0]
# throw exception! blah!
client.checksig()
data = data[4 .. -1]
elements = @@structstat
hash = { }
i = 0
o = 0
while i < elements.length
name = elements[i]
size = elements[i + 1]
i += 2
e = data[o, size].unpack(size == 2 ? 'S' : 'L')[0]
o += size
hash[name] = e
if res < 0 # eek! error!
raise SystemCallError.new(name, -res)
end
return(hash)
return files
end
#
# Instance Methods
#
# setup an instance variable, just for ease and copy it over..
# and so you can change it instance wise
private
attr_accessor :client
public
def initialize()
self.client = self.class.client
end
end
end; end; end # DispatchNinja/Post/Rex

View File

@ -29,6 +29,10 @@ class File < Rex::Post::File
client.checksig()
if res < 0
raise SystemCallError.new(file, -res)
end
return data[4 .. -1]
end
end

View File

@ -22,6 +22,20 @@ class Process < Rex::Post::Process
client.checksig()
return data.unpack('l3')
end
def Process.pid()
client.sendmodule('getpid')
data = client.sockread(4)
client.checksig
return data.unpack('V')[0]
end
def Process.ppid()
client.sendmodule('getppid')
data = client.sockread(4)
client.checksig
return data.unpack('V')[0]
end
end
end; end; end # DispatchNinja/Post/Rex