Tuesday, September 26, 2006

Thursday, September 21, 2006

J2SE 5.0

BlueJ & J2SE5.0 on Mac OS X

1. Get Java 5.

Downoad Java 5 for Tiger from Apple. Install it in the usual way.

2. Make Java 5 the default

The Java 5 installer adds a new utility to your system, called 'Java Preferences'. It is in /Applications/Utilities/Java/J2SE 5.0/Java Preferences.

Start this utility. In the section titled Java Application Runtime Settings, drag J2SE 5.0 to the top of the list of supported versions. Save, and you're done.

BlueJ now uses Java 5. You can, of course, reverse your choice in the same way.

BlueJ

Wednesday, September 20, 2006

find, awk ( Unix )

/*to know the names of all SUID and SGID files.*/

# find / \( -prem -004000 -o -perm -002000 \) -type f -print

(p79, Simson Garfinkel & Gene Spafford, Practical Unix Secutity, O'Reilly & Associates, Inc.)

/*scan disks for unauthorized device files.*/

# find / \( -type c -o -type b \) -exec ls -l {} \;

(p83,)

/*scan for accounts on the computer without passwords*/

# awk -F: 'length($2)<1 {print $1}' < /etc/passwd (/etc/shadow, /etc/secure/passwd)

(p90,)


awk

Practical Unix Secutiry

Practical Unix Secutiry

Monday, September 18, 2006

base64 ( Python )

### test.py ####

import sys, base64

base64.decode( open( sys.argv[ 1 ], 'rb' ), open( sys.argv[ 1 ] + '.jpg', 'wb' ))

#######

in tcsh

> foreach testfile ( * )
> python test.py $testfile
> end

csplit ( Unix )

Split the text with "/9j/4"


csplit -f chap. FILENAME '/\/9j\/4/' '{20}'

-f prefix
/expr/ create file from the current line up to the line
containing the regular expression expr.
{n} Repeat argument n times.


(p 46, UNIX IN A NUTSHELL, O'REILLY)

Saturday, September 16, 2006

base64 ( Python )

A friend emailed me. jpg hadn't been decoded.


------=_NextPart_000_7706_6ba_7d30
Content-Type: image/jpeg; name="image.jpg";
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="image.jpg";

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJ
ChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/
2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo
KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAFQAYsDASIAAhEBAxEB/8QA
HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUF
BAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK
FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1
dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG
x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEB
AQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAEC
AxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRom
JygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOE
hYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU
1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD0XXBmN2UA
AVzljcb5CJDiukvle5h2Kjc9eKzLPRDMZXkby44xkmvRezTPNWpRupEQkKCx
PpVZow7Dy1570+fy/LZ4pMsDjbS2Su/LcE1jayDlsKLX9zjHPsKrPp8hBLKT
6Zrciwi4eobuUovyMK5G5c25py2RzU1k6qWC4GaiCmBicVsvc+ahjZOSetZ9
..........


I used this code to decode the jpg.

##

import sys, base64
base64.decode(open(sys.argv[1],'rb'),open(sys.argv[2],'wb'))

##

ASPN

Monday, September 4, 2006

web

Babylicious

string in Python


for line in open('test.txt').readlines(): print line
for line in open('test.txt').xreadlines():print line
for line in open('test.txt'): print line

for char in open('test.txt').read(): print char
file = open('test.txt')
while 1:
char=file.read(1)
if not char:break
print char,

(p165, Learning Python 2nd edition, O'REILLY)

Crocodile man,Steve Irwin, dies

Crocodile man, Steve Irwin, dies

v3 ( Python )


This task is best handled by two nested loops, one on lines and another on the words in each line:

for line in open(thefilepath):
for word in line.split():
dosomethingwith(word)

p72, Python Cookbook 2nd edition, O'REILLY

#################

#!/usr/bin/env python
import os, sys

input_file = sys.stdin
output_file = sys.stdout
input_file = open( sys.argv[ 1 ] )
output_file = open( sys.argv[ 2 ], 'w' )

original = input_file.read()

str1="""#ifdef DEVELP /* Borland C v3.1 version */
unsigned char VoltTable[] = { \n"""

str2="""0 };\n#endif
#ifdef EMBED /* Dunfield assembler version */
void VoltTable(void) asm { \n"""

str3=""" }
#endif\n"""

def numGet( x ):
count = 0
str = original
s = ""
if x == 2:
s += " DB "
else:
s += "\t"

for ch in str:
if ch == '\r':
count += 1
if count % 16 != 0:
s += ','
else:
if x == 1:
s += ',\n\t'
elif x == 2:
s += '\n DB '
elif ch == '\n':
s += ''
else:
s += ch
if x == 2:
return s[ :-1 ]
else:
return s

result = ""
result = str1 + numGet( 1 ) + str2 + numGet( 2 ) + str3

output_file.write(result)

input_file.close()
output_file.close()

Sunday, September 3, 2006

v2 ( Python )


#!/usr/bin/env python
import os, sys

input_file = sys.stdin
output_file = sys.stdout
output_file = open( sys.argv[ 2 ], 'w' )
input_file = open( sys.argv[ 1 ] )

original = input_file.read()

str1="""#ifdef DEVELP /* Borland C v3.1 version */
unsigned char VoltTable[] = { \n"""

str2="""0 };\n#endif
#ifdef EMBED /* Dunfield assembler version */
void VoltTable(void) asm { \n"""

str3="""}
#endif\n"""

def test( x ):
count = 0
str = original
s = ""
if x == 2:
s += " DB "
else:
s += "\t"

for line in str:
for word in line:
if word == '\r':
count += 1
if count % 16 != 0:
s += ','
else:
if x == 1:
s += ',\n\t'
elif x == 2:
s += '\n DB '
elif word == '\n':
s += ''
else:
s += word
return s

result = ""
result = str1 + test( 1 ) + str2 + test( 2 ) + str3

output_file.write(result)

input_file.close()
output_file.close()


### output ####

#ifdef DEVELP /* Borland C v3.1 version */
unsigned char VoltTable[] = {
3,6,9,12,15,18,21,23,26,29,32,34,37,40,42,45,
47,50,52,55,57,59,62,64,66,68,71,73,75,77,79,81,
83,86,88,90,91,93,95,97,99,101,103,105,106,108,110,112,
113,115,117,118,120,121,123,125,126,128,129,131,132,133,135,136,
138,139,140,142,143,144,146,147,148,149,151,152,153,154,155,157,
158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,
174,175,176,177,178,179,180,181,181,182,183,184,185,185,186,187,
188,189,189,190,191,192,192,193,194,194,195,196,196,197,198,198,
199,200,200,201,201,202,203,203,204,204,205,205,206,206,207,208,
208,209,209,210,210,211,211,212,212,212,213,213,214,214,215,215,
216,216,216,217,217,218,218,218,219,219,220,220,220,221,221,221,
222,222,222,223,223,223,224,224,224,225,225,225,226,226,226,226,
227,227,227,228,228,228,228,229,229,229,229,230,230,230,230,231,
231,231,231,232,232,232,232,233,233,233,233,233,234,234,234,234,
234,235,235,235,235,235,235,236,236,236,236,236,236,237,237,237,
237,237,237,238,238,238,238,238,238,238,239,239,239,239,239,0 };
#endif
#ifdef EMBED /* Dunfield assembler version */
void VoltTable(void) asm {
DB 3,6,9,12,15,18,21,23,26,29,32,34,37,40,42,45
DB 47,50,52,55,57,59,62,64,66,68,71,73,75,77,79,81
DB 83,86,88,90,91,93,95,97,99,101,103,105,106,108,110,112
DB 113,115,117,118,120,121,123,125,126,128,129,131,132,133,135,136
DB 138,139,140,142,143,144,146,147,148,149,151,152,153,154,155,157
DB 158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173
DB 174,175,176,177,178,179,180,181,181,182,183,184,185,185,186,187
DB 188,189,189,190,191,192,192,193,194,194,195,196,196,197,198,198
DB 199,200,200,201,201,202,203,203,204,204,205,205,206,206,207,208
DB 208,209,209,210,210,211,211,212,212,212,213,213,214,214,215,215
DB 216,216,216,217,217,218,218,218,219,219,220,220,220,221,221,221
DB 222,222,222,223,223,223,224,224,224,225,225,225,226,226,226,226
DB 227,227,227,228,228,228,228,229,229,229,229,230,230,230,230,231
DB 231,231,231,232,232,232,232,233,233,233,233,233,234,234,234,234
DB 234,235,235,235,235,235,235,236,236,236,236,236,236,237,237,237
DB 237,237,237,238,238,238,238,238,238,238,239,239,239,239,239,}
#endif