Changeset 4883

Show
Ignore:
Timestamp:
05/06/07 23:42:38 (1 year ago)
Author:
hdm
Message:

This patch adds support for java byte array output (useful for sticking shellcode into java applets).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework3/tags/framework-3.0/lib/rex/text.rb

    r4630 r4883  
    108108 
    109109        # 
     110        # Converts a raw string into a java byte array 
     111        # 
     112        def self.to_java(str) 
     113                buff = "byte shell[] = new byte[]\n{\n" 
     114                cnt = 0 
     115                max = 0 
     116                str.unpack('C*').each do |c| 
     117                        buff << ", " if max > 0 
     118                        buff << "\t" if max == 0 
     119                        buff << sprintf('(byte) 0x%.2x', c) 
     120                        max +=1 
     121                        cnt +=1  
     122                         
     123                        if (max > 7)     
     124                                buff << ",\n" if cnt != str.length  
     125                                max = 0 
     126                        end 
     127                end 
     128                buff << "\n};\n" 
     129                return buff      
     130        end 
     131         
     132        # 
    110133        # Creates a perl-style comment 
    111134        # 
     
    382405 
    383406        # 
     407        # Converts a string a nicely formatted hex dump 
     408        # 
     409        def self.to_hex_dump(str, width=16) 
     410                buf = '' 
     411                idx = 0 
     412                cnt = 0 
     413                snl = false 
     414                lst = 0 
     415                 
     416                while (idx < str.length) 
     417                         
     418                        chunk = str[idx, width] 
     419                        line  = chunk.unpack("H*")[0].scan(/../).join(" ") 
     420                        buf << line      
     421 
     422                        if (lst == 0) 
     423                                lst = line.length 
     424                                buf << " " * 4 
     425                        else 
     426                                buf << " " * ((lst - line.length) + 4).abs 
     427                        end 
     428                         
     429                        chunk.unpack("C*").each do |c| 
     430                                if (c > 0x19 and c < 0x80) 
     431                                        buf << c.chr 
     432                                else 
     433                                        buf << "." 
     434                                end 
     435                        end 
     436                         
     437                        buf << "\n" 
     438                 
     439                        idx += width 
     440                end 
     441                 
     442                buf << "\n" 
     443        end 
     444         
     445        # 
    384446        # Converts a hex string to a raw string 
    385447        #