Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Last active February 21, 2017 04:09
Show Gist options
  • Save thomasjslone/72fd94094228674122f7cc407607aaae to your computer and use it in GitHub Desktop.
Save thomasjslone/72fd94094228674122f7cc407607aaae to your computer and use it in GitHub Desktop.
Ruby Development Runtime/Debug Environment
#T#;#O#;#P#;#F#
require "rbconfig"
module AddExec ; def exec(r) ; begin ; eval(r.to_s) ; rescue => e ; e.backtrace.join("\n").to_s ; end ; end ; end
OS = "UNKNOWN" ; if RbConfig::CONFIG["host_os"] == "linux" and RbConfig::CONFIG["host_vendor"] == "The Android Project" ; OS = "ANDROID" ; elsif RbConfig::CONFIG["host_os"] == "mingw32" or RbConfig::CONFIG["host_os"] == "mingw64" ; OS = "WINDOWS" ; end
if OS == "ANDROID"
SYS_DIR = ENV["ANDROID_ROOT"].to_s
elsif OS == "WINDOWS"
SYS_DIR == Dir.home.to_s
else
SYS_DIR = Dir.getwd.to_s
end
RUBY_DIR = Dir.getwd.to_s
OSSY_DIR = RUBY_DIR.to_s + "/ossy"
CPU = RbConfig::CONFIG["host_cpu"]
ENV_ARCH = RbConfig::CONFIG["arch"]
OSSY_VER = "V1.0.4"
##;##;##;##;##;##;##;##
def read_file(p) ; if File.exist?(p) ; fi = File.open(p,"r") ; cont = fi.read.to_s ; fi.close ; cont.to_s ; else ; "NON-EXISTENT: " + p.to_s ; end ; end
def write_file(p,v) ; begin ; if File.directory?(p.to_s.split("/")[0..-2].join("/").to_s) ; fi = File.open(p,"w") ; fi.write(v.to_s) ; fi.close ; true ; else ; "NON-EXISTENT: " + p.to_s ; end ; rescue ; "Could not access file." ; end ; end
def copy_file(p,np) ; if File.exist?(p) ; begin ; fi = File.open(p.to_s,"r") ; cont = fi.read.to_s ; fi.close ; fi = File.open(np.to_s + "/" + p.to_s.split("/")[-1].to_s,"w") ; fi.write(cont.to_s) ; fi.close ; true ; rescue ; false ; end ; else ; false ; end ; end
def clone_file(p,np) ; if File.exist?(p) ; begin ; fi = File.open(p.to_s,"r") ; cont = fi.read.to_s ; fi.close ; name = p.to_s.split("/")[-1].to_s ; if name.include?(".") ; ext = "." + name.to_s.split(".")[0..-2].join(".").to_s ; else ; ext = "" ; end ; nn = np.to_s + "/" + name.to_s + ext.to_s ; if File.exist?(nn.to_s) ; until File.exist?(nn) == false ; nn = np.to_s + "/" + name.to_s + c.to_s + ext.to_s ; c += 1 ; end ; end ; fi = File.open(nn.to_s,"w") ; fi.write(cont.to_s) ; fi.close ; true ; rescue ; false ; end ; else ; false ; end ; end
def move_file(p,np) ; fail = nil ; if File.exist?(p) and File.directory?(np) and File.exist?(np.to_s + "/" + p.to_s.split("/")[-1].to_s) == false ; begin ; fi = File.open(p,"r") ; cont = fi.read.to_s ; fi.close ; fi = File.open(np.to_s + "/" + p.to_s.split("/")[-1].to_s,"w") ; fi.write(cont) ; rescue ; fail = true ; end ; if File.exist?(np.to_s + "/" + p.to_s.split("/")[-1].to_s) and fail.to_s == "" ; File.delete(p) ; true ; else ; false ; end ; else ; false ; end ; end
def rename_file(p,nn) ; if File.exist?(p.to_s.split("/")[0..-2].join("/").to_s + "/" + nn.to_s) == false ; File.rename(p,nn) ; true ; else ; false ; end ; end
def delete_file(p) ; if File.exist?(p) ; begin ; File.delete(p) ; true ; rescue ; false ; end ; else ; false ; end ; end
def empty_file(p) ; if File.exist?(p) ; begin ; fi = File.open(p) ; fi.write('') ; fi.close ; true ; rescue ; false ; end ; else ; false ; end ; end
def search_file(p,str) ; if File.exist?(p) ; begin ; fi = File.open(p,"r") ; cont = fi.read.to_s ; fi.close ; cont.to_s.downcase.include?(str.to_s.downcase) ; rescue ; false ; end ; else ; false ; end ; end
def read_folder(p) ; if File.directory?(p) ; objs = [] ; begin ; Dir.entries(p).each { |e| if e.to_s != "." and e.to_s != ".." ; objs << p.to_s + "/" + e.to_s ; end } ; objs ; rescue ; false ; end ; else ; "NON-EXISTENT: " + p.to_s ; end ; end
def create_folder(p) ; if File.directory?(p.to_s.split("/")[0..-2].join("/").to_s) and p.to_s.split("/")[-1].to_s.length > 0 ; begin ; Dir.mkdir(p) ; true ; rescue ; false ; end ; else ; false ; end ; end
#def copy_folder(p) ; ; end
#def move_folder(p) ; ; end
def rename_folder(p,nn) ; if File.directory?(p) and File.directory?(p.to_s.split("/")[0..-2].join("/").to_s + "/" + nn.to_s) == false ; dont_move = false ; m = map_folder(p) ; fc = [] ; i = 0 ; if m[0].length > 0 ; m[1].each do |f| ; begin ; fi = File.open(f,"r") ; fc << fi.read.to_s ; i += 1 ; rescue ; dont_move = true ; end ; end ; end ; if dont_move == false ; nfin, nfon = [], [] ; dirn = p.to_s.split("/")[-1].to_s ; m[1].each { |fn| nfin << fn.to_s.split(dirn)[0].to_s + nn + fn.to_s.split(dirn)[-1].to_s } ; m[2].each { |fn| if fn.to_s.split(dirn).length > 1 ; nfon << fn.to_s.split(dirn)[0].to_s + nn.to_s + fn.to_s.split(dirn)[1..-1].join(dirn).to_s ; else ; nfon << fn.to_s.split(dirn)[0].to_s + nn.to_s ; end } ; nfon.each { |fo| Dir.mkdir(fo) } ; c = 0 ; nfin.each { |fi| fi = File.open(fi,"w") ; fi.write(fc[c].to_s) ; fi.close ; c += 1 } ; delete_folder(p) ; true ; else ; false ; end ; else ; false ; end ; end
def delete_folder(p) ; if File.directory?(p) ; m = map_folder(p) ; if m[1].length > 0 ; m[1].each { |f| begin ; File.delete(f) ; rescue ; ; end } ; end ; if m[2].length > 0 ; m[2].each { |d| begin ; Dir.rmdir(d) ; rescue ; ; end } ; end ; begin ; Dir.rmdir(p) ; true ; rescue ; false ; end ; else ; false ; end ; end
def empty_folder(p) ; if File.directory?(p) ; m = map_folder(p) ; if m[1].length > 0 ; m[1].each { |f| begin ; File.delete(f) ; rescue ; ; end } ; end ; if m[2].length > 0 ; m[2].each { |f| begin ; Dir.rmdir(f) ; rescue ; ; end } ; end ; if Dir.entries(p) == [".",".."] ; true ; else ; false ; end ; else ; false ; end ; end
#def search_folder(p,t) ; ; end
def map_folder(dir) ; if File.directory?(dir) ; remaining = [dir] ; found_files = [] ; file_size = [] ; found_folders = [] ; until remaining.length == 0 ; cur_dir = remaining[0].to_s ; remaining.delete_at(0) ; begin ; cont = Dir.entries(cur_dir) ; cont.delete(".") ; cont.delete("..") ; rescue ; cont = [] ; end ; if cont.length > 0 ; cont.each do |obj| ; if File.file?(cur_dir.to_s + "/" + obj.to_s) ; found_files << cur_dir.to_s + "/" + obj.to_s ; file_size << File.size?(found_files[-1]) ; elsif File.directory?(cur_dir.to_s + "/" + obj.to_s) ; found_folders << cur_dir.to_s + "/" + obj.to_s ; remaining << cur_dir.to_s + "/" + obj.to_s ; end ; end ; else ; end ; end ; return [file_size,found_files,found_folders] ; else "DIRECTORY NON-EXISTENT: " + dir.to_s ; end ; end
def ftype?(p) ; if File.directory?(p) ; "DIRECTORY" ; elsif File.file?(p) ; "FILE" else ; "FALSE" ; end ; end
def fexist?(p) ; if File.directory?(p) or File.file?(p) ; true ; else ; false ; end ; end
def splice(str,b,e) ; res = [] ; loop do ; p = str[/#{b}(.*?)#{e}/m, 1].to_s ; if p.to_s.length == 0 ; break ; else ; res << p ; str = str.split(b + p + e)[-1].to_s ; end ; end ; return res ; end
def starts_with(string,tag) ; chk = true ; i = 0 ; string.to_s.split("").each { |ch| if ch.to_s != tag.to_s[i].to_s ; chk = false ; end ; if i + 1 == tag.length.to_i ; break ; else ; i += 1 ; end } ; chk ; end
def ends_with(string,tag) ; string = string.reverse ; tag = tag.reverse ; chk = true ; i = 0 ; string.to_s.reverse.split("").each { |ch| if ch.to_s != tag.to_s[i].to_s ; chk = false ; end ; if i + 1 == tag.length.to_i ; break ; else ; i += 1 ; end } ; chk ; end
def list_spacer(spaces,left,right) ; width = spaces .to_i+ 5 ; str = '' ; left.each do |l| ; spacer = "" ; t = width - l.length.to_i ; t.to_i.times { spacer << " " } ; str << l.to_s + spacer.to_s + right[left.index(l)].to_s + "\n" ; end ; return str.to_s ; end
def fnum(n) ; str = "" ; s = n.to_s.split("").reverse ; i=0 ; s.each do |nc| ; if i == 2 ; i=0 ; str << nc.to_s + "," ; else ; str << nc.to_s ; i+=1 ; end ; end ; if str.to_s[-1].to_s == "," ; str = str.reverse.to_s.split("")[1..-1].join("").to_s ; else ; str = str.reverse.to_s ; end ; return str ; end
#def wrap(str,l) ; ; end
#def frame(str,mat,thk,dns)
def rands(l) ; key = "" ; l.times { key << rand(10**8..10**9).to_s(36).to_s[rand(6).to_i].to_s } ; key.to_s ; end
def exponate(n) ; c=2 ; e=2 ; r = [0,0] ; until c > n ; e = 2 ; until e >= n ; if c**e == n ; return [c,e] ; end ; e += 1 ; end ; c += 1 ; end ; end
def factors(n) ; p = [2] ; vn = 2 ; until vn == n ; vn += 1 ; p << vn ; end ; p.delete_at(-1) ; f1 = 0 ; f2 = 0 ; pd = [] ; p.each do |pn| ; s = n.to_f / pn.to_f ; if s.to_s[-2..-1].to_s == ".0" ; pd << pn ; end ; end ; pd.each do |p| ; if p * p == n ; f1, f2 = p, p ; else ; cd = pd ; cd.delete(p) ; cd.each do |pr| ; if p * pr == n ; f1, f2 = p, pr ; break ; end ; end ; end ; end ; return [f1,f2] ; end
def numerize(str) ; if str == "" ; return 0 ; else ; chbytes = ["97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "126", "96", "33", "64", "35", "36", "37", "94", "38", "42", "40", "41", "45", "95", "61", "43", "91", "93", "123", "125", "59", "58", "34", "39", "92", "47", "124", "63", "60", "62", "44", "46", "32", "9", "10"] ; ch_inds = [] ; str.to_s.split("").each { |ch| ch_inds << chbytes.index(ch.to_s.ord.to_s) } ; enc = [] ; ch_inds.each do |ch| ; code = ch.to_i + 1 ; if code.to_s.length == 1 ; code = "0" + code.to_s ; else ; code = code.to_s ; end ; enc << code.to_s ; end ; enc = enc.join("").to_s ; if enc.to_s[0].to_s == "0" ; enc = enc[1..-1].to_s ; end ; return enc.to_s ; end ; end
def denumerize(str) ; kbchars = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9","~","`","!","@","#","$","%","^","&","*","(",")","-","_","=","+","[","]","{","}",";",":","\"","'","\\","/","|","?","<",">",",","."," ","\t","\n"] ; if str.to_s.length.odd? ; str = "0" + str.to_s ; end ; str_codes = [] ; i = 0 ; hold = "" ; str.to_s.split("").each do |num| ; if i.to_i == 0 ; hold << num.to_s ; i += 1 ; elsif i.to_i == 1 ; hold << num.to_s ; i = 0 ; str_codes << hold.to_s ; hold = "" ; end ; end ; str = str_codes ; str_codes = [] ; str.each do |c| ; str_codes << c.to_i - 1 ; end ; dec_str = "" ; str_codes.each { |c| dec_str << kbchars[c.to_i].to_s } ; dec_str.to_s ; end
def get_timestamp ; Time.now.to_s.split(" ")[0..1].join(".").split(":").join(".").split("-").join(".").to_s ; end
#def internet? ; ; end
#def wifi? ; ; end
#def wifi_name? ; ; end
#def wifi_connected? ; ; end
#def connect_to_wifi(host)
#def disconnect_from_wifi(host)
#def ping(addr)
#def get_page(url) ; ; end
#def get_file(fttp) ; ; end
#def send_file(addr,file)
#def bluetooth? ; ; end
#def bluetooth_on? ; ; end
#def bluetooth_paired? ; ; end
#def bluetooth_pair(host) ; ; end
#def bluetooth_unpair(host) ; ; end
#def lan? ; ; end
#def lan_connected? ; ; end
#def lan_name? ; ; end
#def cpu_model? ; ; end
#def cpu_cores? ; ; end
#def cpu_cur? ; ; end
#def cpu_max? ; ; end
#def ram_model? ; ; end
#def ram_cur?
#def ram_max?
#def hostdir? ; ; end
#def host_root? ; ; end
#def os_name? ; ; end
#def os_version? ; ; end
#def firmware? ; ; end
#def ruby_version? ; ; end
#def ruby_dir? ; ; end
#def ruby_install_dir? ; ; end
##;##;##;##;##;##;##;##
def s ; $ossy.r "shell" ; end
def r str ; $ossy.r str ; end
##;##;##;##;##;##;##;##
class Ossy
def initialize
if File.exist?(OSSY_DIR.to_s + "/one_time_config.cfg")
begin
fi = File.open(OSSY_DIR.to_s + "/one_time_config.cfg","r")
eval(fi.read.to_s)
File.delete(OSSY_DIR.to_s + "/one_time_config.cfg")
rescue
#$log.write("Startup One Time Config Failed")
#self.config_failed
end
elsif File.exist?(OSSY_DIR.to_s + "/config.cfg")
begin
fi = File.open(OSSY_DIR.to_s + "/config.cfg","r") ; eval(fi.read.to_s) ; fi.close
rescue
#$log.write("Startup One Time Config Failed")
#self.config_failed
end
end
## startup finished
end
def r(cmd)
if cmd.to_s == "shell" ; if OS == "ANDROID" ; $irb.start_ruboto_activity :class_name => "RShell_Android_Activity" ; else ; "You need a shell app that uses guis that can be accessed on your operating system, if one does not exist you might build one." ; end
elsif cmd.to_s == ""
elsif cmd[0..4].to_s == "ratc:"
c = cmd[5..-1].to_s ; if c.to_s[0] == "$" ; begin ; obj = c ; c.class.class_eval { include AddExec } ; true ; rescue ; false ; end ; else ; false ; end
elsif cmd.to_s == ""
elsif cmd.to_s == "s<" ; system(cmd)
elsif cmd.to_s[0..1] == "o<" ; if $ossy.class == "Ossy" ; res = $ossy.r(cmd[2..-1].to_s) ; else ; "Ossy has not been initialized." ; end
else ; begin ; res = eval(cmd) ; rescue => e ; res = e.backtrace.join("\n").to_s ; end
end
if res == nil
"NilClass"
elsif res == ""
"NilString"
else
res
end
end
def rat_class(obj) ; begin ; obj.class_eval { include AddExec } ; true ; rescue ; false ; end ; end
end ; $ossy = Ossy.new
##;##;##;##;##;##;##;##
class Dictionary
def initialize ; @words = [] ; if File.exist?("/mnt/sdcard/jruby/ossy/dictionary.txt") ; load ; else ; save ; end ; end
def count ; @words.length ; end
def get(r) ; if r == true ; @words ; elsif r.is_a? Integer and r + 1 <= @words.length or r.is_a? Range ; @words[r] ; elsif r.is_a? String and @words.include?(r) ; @words.index(r) ; else ; false ; end ; end
def set(r,w) ;if r == true ; @words = w.to_a ; true ; elsif r.is_a? Integer and r + 1 <= @words.length ; @words[r] = w ; true ; elsif r.is_a? String and @words.include?(r) ; @words[@words.index(r)] = w ; true ; elsif r.is_a? Range and w.is_a? Array ; @words[r] = w ; true else ; false ; end ; end
def add(words) ; c = 0 ; digest(words).each do |i| ; unless @words.include?(i.to_s.downcase) ; @words << i.to_s.downcase ; c += 1 ; end ; end ; if c > 0 ; c ; else ; false ; end ; end
def rem(words) ; c = 0 ; words.to_s.split(" ").join(" ").split(" ").each { |i| ; if @words.include?(i.downcase) ; @words.delete(i.downcase) ; c += 1 ; end } ; if c > 0 ; c ; else ; false ; end ; end
def digest(str) ; str.tr("~`!@#$%^&*()-=_+[]{}|\\:;\"'<>?,\n\t", " ").split(" ").join(".").split(".") ; end
def search(str) ; f = [] ; i = [] ; c = 0 ; @words.each { |w| if w.include?(str.to_s.downcase) ; f << w.to_s ; i << c ; end ; c += 1 } ; if f > 0 ; [f,i] ; else ; false ; end ; end
def scan(dir) ; if File.directory?(dir) ; $scan_thread = Thread.new{ m = map_folder(dir) ; $added = 0 ; $total = m[0].length.to_i ; $done = 0 ; m[1].each do |fp| ; begin ; fi = File.open(fp.to_s,"r") ; $added += add(fi.read.to_s).to_i ; fi.close ; File.delete(fp) ; $done += 1 ; rescue ; end ; end ; $added.to_i } ; else ; "No such directory: " + dir.to_s ; end
end
def scan_info
p = $done.to_f / $total.to_f * 100 ; p = p.to_s.split(".")[0].to_s + "." +p.to_s.split(".")[1][0..1].to_s
str = ""
str << "Files Processed: " + $done.to_s + " / " + $total.to_s + ", % " + p.to_s + ", Words Added: " + $added.to_s
end
def import(dir) ; if File.exist?(dir) ; fi = File.open(dir.to_s,"r") ; cont = fi.read.to_s ; fi.close ; add(cont.to_s) ; else ; "No such file: " + dir.to_s ; end ; end
def save ; begin ; fi = File.open("/mnt/sdcard/jruby/ossy/dictionary.txt","w") ; fi.write(@words.to_s) ; fi.close ; true ; rescue ; false ; end ; end
def load ; begin ; fi = File.open("/mnt/sdcard/jruby/ossy/dictionary.txt","r") ; @words = eval(fi.read.to_s).to_a ; true ; rescue ; false ; end ; end
end
##;##;##;##;##;##;##;##
class Simpleton_Cipher
def initialize ; @chset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,./;'[]-=<>?:\"{}_+)(|\\*&^%$#@!~` \n" ; end
def generate_key ; key = @chset ; rand(1..10).times { key = key.split('').shuffle.join('').to_s } ; key ; end
def encode(str,key) ; str.tr(@chset, key) ; end
def decode(str,key) ; str.tr(key, @chset) ; end
end
##;##;##;##;##;##;##;##
class Matrix
#def initialize(x,y,init) ; @x = x ; @y = y ; @init = init ; row = [] ; y.times { row << @init } ; @matrix = [] ; x.times { @matrix << row } ; end
#def get(x,y) ; if x.is_a? Integer or x.is_a? Range and y.is_a? Integer or y.is_a? Range ; @matrix[x][y] ; end ; end
#def set(x,y,v) ; if x.is_a? Integer and y.is_a? Integer ; @matrix[x][y] = v ; true ; elsif x.is_a? Range and y.is_a? Integer ; rows = @matrix[x] ; rows.each { |r| r[y] = v} ; @matrix[x] = rows ; true ; elsif x.is_a? Integer and y.is_a? Range ; dif = y.to_s.split("..")[1].to_i - y.to_s.split("..")[0].to_i ; dif += 1 ; v = [] ; dif.times { vv << v} ; @matrix[x][y] = vv ; true ; elsif x.is_a? Range and y.is_a? Range ; dif = y.to_s.split("..")[1].to_i - y.to_s.split("..")[0].to_i ; dif += 1 ; vv = [] ; dif.times { vv << v } ; rows = @matrix[x] ; rows.each { |r| r[y] = vv } ; @matrix[x] = rows ; true ; end ; end
#def get_row(d,i) ; if d == "x" ; @matrix[i] ; elsif d == "y" ; row = [] ; @matrix.each do |r| ; row << r[i] ; end ; row ; end ; end
#def set_row(d,i,v) ; ; end
#def trim_x(m,n) ; ; end
#def trim_y(m,n) ; ; end
#def infect(v) ; @matrix = [] ; row = [] ; @y.times { row << v } ; @x.times { @matrix << row } ; true ; end
#def include?(v) ; i = [0,0] ; f = false ; c = 0 ; @matrix.each do |r| ; if r.include?(v) ; i[1] = r.index(v) ; f = true ; break ; else ; i[0] += 1 ; end ; if f ; i ; else ; false ; end ; end ; end
#def unistate? ; v = true ; c = @matrix[0][0] ; @matrix.each do |r| ; r.each do |i| ; if i != c ; v = false ; break ; end ; unless v ; break ; end ; end ; v ; end
#def size? ; [@matrix[0..-1].length,@matrix[0].length] ; end
# def data_size? ; t = 0 ; @matrix.each do |r| ; r.each { |i| t += i.to_s.length } ; end ; t ; end
end
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
require 'ruboto/activity' ; require 'ruboto/widget' ; require 'ruboto/util/toast' ; ruboto_import_widgets :TextView, :LinearLayout, :Button, :ListView, :EditText
class RShell_Android_Activity
def on_create(b)
super
if $ossy != nil ; @parent_object = $ossy ; @parent_access_method = "r" ; else @parent_object = nil ; @parent_access_method = "" ; end
build_ui("shell")
end
def build_ui(ui)
if ui.to_s == "shell"
if @parent_object != nil ; p = " : " + @parent_object.to_s ; else ; p = "" ; end
setTitle "RubyShell" + p.to_s
set_content_view(linear_layout(:orientation => :vertical) do
@fid = 0 ; scl = 10 ; $scl = scl - scl - scl ; @sc1 = $scl ; @sc2 = -1 ; $display_lines = [] ; scl.times { $display_lines << "" }
@display = text_view :text => $display_lines.join("\n") ; @wrap_length = 95
set_content_view(linear_layout(:orientation => :horizontal) do
@fid_label = text_view :text => "<" + @fid.to_s + ": "
@input_bar = edit_text
button :text => "E", :on_click_listener => (proc{forward_input}) , :height => 60 , :width => 40
end)
end)
elsif ui.to_s == "login"
setTitle "Log into shell."
set_content_view(linear_layout(:orientation => :horizontal) do
@inpb = edit_text :width => :wrap_content, :hint => 'password', :transformation_method => android.text.method.PasswordTransformationMethod.new
button :text => "Log In", :on_click_listener => (proc{ @password = @inpb.get_text.to_s ; build_ui("shell") ; append_consol("Welcome to the shell.") }) , :height => 47 , :width => 87
end)
end
end
def append_consol(inp) ; scroll_bottom ; ll = [] ; inp.to_s.split("\n").each { |l| ll << l.to_s } ; nl = [] ; ll.each do |l| ; if l.to_s.length > @wrap_length.to_i ; c = 0 ; line = "" ; l.split('').each { |ch| if c < @wrap_length.to_i - 1 ; line << ch.to_s ; c += 1 ; else ; nl << line.to_s + ch.to_s ; line = "" ; c = 0 ; end } ; else ; nl << l.to_s ; end ; end ; nl.each { |l| $display_lines << l.to_s } ; update_display ; end
def update_display ; @display.set_text($display_lines[@sc1..@sc2].join("\n").to_s) ; end
def set_display_lines(lines) ; $scl = lines.to_i - lines.to_i - lines.to_i ; @sc1 = $scl ; update_display ; end
def set_display_width(length) ; @wrap_length = length.to_i ; end
def scroll_top ; l = $display_lines.length.to_i ; l = l - l - l ; @sc1 = l.to_i ; @sc2 = @sc1 - $scl - 2 ; update_display ; end
def scroll_up ; cpv = $display_lines.length - $display_lines.length - $display_lines.length ; if @sc1.to_i > cpv.to_i ; @sc1 -= 1 ; @sc2 -= 1 ; update_display ; else ; ; end ; end
def scroll_bottom ; @sc1 = $scl ; @sc2 = -1 ; update_display ; end
def scroll_down ; if @sc2.to_i < -1 ; @sc1 += 1 ; @sc2 += 1 ; update_display ; else ; ; end ; end
def forward_input
cmd = @input_bar.get_text.to_s ; @input_bar.set_text("") ; res = ""
if cmd[0].to_s == "*" ; cmd = cmd[1..-1].to_s ; @input_bar.set_text("*" + cmd.to_s) ; end
if cmd.to_s == "[u" ; res = nil ; scroll_up ; @fid -= 1
elsif cmd.to_s == "[d" ; res = nil ; scroll_down ; @fid -= 1
elsif cmd.to_s == "[h" ; res = nil ; scroll_top ; @fid -= 1
elsif cmd.to_s == "[e" ; res = nil ; scroll_bottom ; @fid -= 1
elsif cmd[0..2].to_s == "[h:" ; l = cmd.to_s[3..-1].to_i ; if l >= 5 ; set_display_lines(l) ; else ; res = "[h: must be >= 5" ; end ; @fid -= 1
elsif cmd[0..2].to_s == "[w:" ; w = cmd[3..-1].to_i ; if w >= 50 ; set_display_width(w) ; else ; res = "[w: must be >= 50" ; end ; @fid -= 1
elsif cmd.to_s[0..1] == "s<" ; begin ; res = eval(cmd.to_s[2..-1].to_s) ; rescue ; res = "Ruby Failed" ; end
elsif cmd.to_s == "p?"
append_consol("<" + @fid.to_s + ": " + cmd.to_s)
res = "Parent Object: " + @parent_object.to_s + ", Access Method: " + @parent_access_method.to_s + "(str)"
elsif cmd.to_s == "p!"
append_consol("<" + @fid.to_s + ":" + cmd.to_s) ; setTitle "RubyShell"
@parent_object = nil ; @parent_access_method = ""
res = "Parent object was removed."
elsif cmd.to_s[0..1] == "p:"
append_consol("<" + @fid.to_s + ": " + cmd.to_s)
obj = cmd.to_s[2..-1].to_s.split(";")[0]
@parent_object = eval(obj.to_s)
@parent_access_method = cmd.to_s[2..-1].to_s.split(";")[1].to_s
res = ":" [email protected]_s + ">" + @parent_object.class.to_s + " was attached successfully." ; setTitle "RubyShell : " + @parent_object.to_s
elsif cmd[0..4] == "ratc:"
append_consol("<" + @fid.to_s + ": " + cmd.to_s)
begin
obj = eval(cmd[5..-1].to_s) ; @parent_object = obj ; @parent_access_method = "exec"
$ossy.rat_class(obj) ; setTitle "RShell : " + @parent_object.to_s
res = "Class was ratted with success. You're now in the class's context."
rescue
res = "Class could not be ratted."
end
elsif cmd.to_s == "exit"
finish
else
if @parent_object == nil
append_consol("<" + @fid.to_s + ": " + cmd.to_s)
begin ; res = eval(cmd.to_s) ; rescue => e ; res = e.backtrace.join("\n").to_s ; end
else
append_consol("<" + @fid.to_s + ":" + cmd.to_s.split("\n").join(" ; ").to_s)
begin ; res = eval("@parent_object." + @parent_access_method.to_s + " '" + cmd.to_s + "'").to_s ; rescue => e ; res = e.backtrace.join("\n").to_s ; end
end
end
if res != nil and res != ""
append_consol(":" + @fid.to_s + ">" + res.to_s)
end
@fid += 1 ; @fid_label.set_text(@fid.to_s)
end
end
##;##;##;##;##;##;##;##
class RShell_Windows_Consol
def initialize
@consol_stream = []
@input_history = []
@output_history = []
@fid = 0
end
def r (cmd)
end
end
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
## Bibler ; V1.0
## Ruby bible search/processing API class
class Bibler
def initialize
@versions = []
@editions = []
@data = []
end
def load ; fi = File.open("/mnt/sdcard/jruby/ossy/bible_data.txt","r") ; cont = fi.read.to_s ; fi.close ; @data = eval(cont.to_s) ; true ; end
def search_a(str) ## get versions.books.chapters.veruses containing tag
end
def search_b(str,filter) ## count occurences of the search word or phrase
end
def search_c(str,filter) ## show a few surrounding verses of the tag
end
end
##;##;##;##;##;##;##;##
##;##;##;##;##;##;##;##
## env_prep
## utility_methods
## shortcut methods
## ossy
## class lib
## updater
class Ossy_Updater
def initialize
@location = __FILE__
end
private ; def get_source ; fi = File.open(__FILE__,"r") ; src = fi.read.to_s ; fi.close ; src.to_s ; end
private
def process_image(src) # turn source into array of strings
src = src.to_s.split("##;##;##;##" + ";##;##;##;##")
env_prep = src[0].to_s.split("#T#;#O#;#P" + "#;#F#")[-1].to_s
utility_methods = src[1].to_s
shortcut_methods = src[2].to_s
classes = src[4..-2]
ossy = src[3].to_s
updater = src[-1].to_s
img = [env_prep.to_s,utility_methods.to_s,shortcut_methods.to_s,classes,ossy.to_s,updater.to_s]
end
private
def process_updated_image(img) # turn image back into one source code string
sep = "##;##;##;##" + ";##;##;##;##" ; begginer = "#T#;#O#" + ";#P#;#F#" ; ender = #B#;#O#;#T#;#T" + "#;#O#;#M#;#F#
img[3] = img[3].join(sep.to_s).to_s
src = beginner.to_s + img.join(sep.to_s).to_s + ender.to_s
return src.to_s
end
private
def update_source(src)
begin
fi = File.open(@location.to_s,"r") ; update_backup = fi.read.to_s ; fi.close
fi = File.open(@location.to_s.split("/")[0..-2].join("/").to_s +"/ossy update backup " + Time.now.to_s + ".enc","w") ; fi.write(numerize(update_backup.to_s).to_s)
fi = File.open(@location.to_s,"w") ; fi.write(src.to_s) ; fi.close
true
rescue
false
end
end
end
##;##;##;##;##;##;##;##
#B#;#O#;#T#;#T#;#O#;#M#;#F#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment