Join Today
+ Reply to Thread
Page 1 of 6 12345 ... LastLast
Results 1 to 10 of 53
  1. #1
    Join Date
    Jun 2005
    Location
    Houston, USA
    Posts
    349

    Default rms class with stream function to exchange data with linux

    Hello guys,

    as it seems to be that some guys are interested in exchange information between j2me and the underlaying linux I will post my rms j2me class here. This class ist to be able with the demon (u may find the demon in the cy4th app in dl section as included bash script file) together exchange data. As the demon has all permissions of linux it is possible from j2me that u have access to the whole underlaying linux if the demon is running. This undermines the security of the java sand box seriously and u must know what u are doing! Don't ask me to get ur files back if u mistaken deleted them!


    But, please hold the code secret and don't spread it to guys which have no permission to this area, as I don't know @ the moment what to do next with the code. It's my own code and copyrighted, but anyone has access to this section here are given permission to use this code for any use (commercial or private), as long as the code itself is not visible to other people. No guarantee - using of own risk! Enjoy!

    Code:
    /*
     * rms.java
     *
     * Created on July 11, 2005, 1:01 AM
     *
     * To change this template, choose Tools | Options and locate the template under
     * the Source Creation and Management node. Right-click the template and choose
     * Open. You can then make changes to the template in the Source Editor.
     */
    
    /**
     *
     * @author Gottfried J. M. Grosshans
     *
     *Description of static class api:
     *rms.loadres(string) returns a string with file contents as stream. Input string is the filename
     *  while in rms class, this is no rms function. It reads a file from the jar file.
     *rms.delete(string) deletes rms file. input string is filename
     *rms.list() returns a list of all rms files
     *rms.save(string1, string2) saves string1 in file with filename string2
     *rms.load(string) returns a string with file contents from a rms file. Input string is the filename
     */
    
    import javax.microedition.rms.*;
    import javax.microedition.midlet.*;
    import java.lang.*;
    import java.io.*;
    import java.util.*;
            
    public class rms {
        
        public static final String loadres(String datei) {
            try {
                InputStream is = rms.class.getResourceAsStream(datei);
                StringBuffer str = new StringBuffer();
                byte b[] = new byte[1];
    
                while ( is.read(b) != -1 ) {
                    str.append(new String(b));
                }
                is.close();
                return str.toString();
            }
            catch (IOException e) {
                e.printStackTrace();
                return null;
            }     
        }
        
        public static final void delete(String delete) {
            try {
            RecordStore.deleteRecordStore(delete);
            } catch (Exception e) {
            // Do some exception handling here
            }
        } 
        
        public static final String[] list() {
            try {
            String[] output = RecordStore.listRecordStores();
            return output;
            } catch (Exception e) {
                return null;
            }
        }
        
        public static final void save(String input, String datei) {
        RecordStore SettingStore;
        ByteArrayOutputStream baos;
        DataOutputStream dos;
        byte[] data;
    
        try {
          SettingStore = RecordStore.openRecordStore(datei,true);
          if(SettingStore==null) return;
    
          baos = new ByteArrayOutputStream();
          dos  = new DataOutputStream(baos);
    
          dos.writeUTF(input);
    //      dos.writeInt(mScore);
    
          data = baos.toByteArray();
          if(SettingStore.getNumRecords()==0)
            SettingStore.addRecord(data,0,data.length);
          else
            SettingStore.setRecord(1, data, 0, data.length);
          SettingStore.closeRecordStore();
    
          dos.close();
          baos.close();
    
        } catch (Exception e) {
    //      System.out.println("rms settings ex:" + e);
    //      e.printStackTrace();
        }
      } 
      
      public static final String load(String datei) {
    
        RecordStore SettingStore;
        ByteArrayInputStream bais;
        DataInputStream dis;
        byte[] data;
        int i;
        String output;
    
        try {
          SettingStore = RecordStore.openRecordStore(datei,false);
          if(SettingStore==null) return "";
    
          data = SettingStore.getRecord(1);
          bais = new ByteArrayInputStream(data);
          dis  = new DataInputStream(bais);
    
          output=dis.readUTF();
    //      mScore=dis.readInt();
    
          dis.close();
          bais.close();
          return output;
    
        } catch (Exception e) {   };
          return "";
      }    
        
        /**
         * Creates a new instance of rms 
         */
        public rms() {
        }
        
    }
    % New UNIX password:
    > penis
    BAD PASSWORD: it's WAY too short
    % New UNIX password:

  2. #2
    Join Date
    Jun 2005
    Location
    Houston, USA
    Posts
    349

    Default Re: rms class with stream function to exchange data with lin

    And here is my code using within cy4th to communicate with the demon:

    Code:
                    String cy4thsts = rms.loadres("cy4th.sts");
                    rms.save("\n" + "cytux" + input.getString(), "cy4thcmd");
                    while (rms.loadres("cy4th.sts").equals(cy4thsts))
                        ;
                    output.setString(rms.loadres("cy4th.out") + rms.loadres("cy4th.err"));
    % New UNIX password:
    > penis
    BAD PASSWORD: it's WAY too short
    % New UNIX password:

  3. #3
    Join Date
    Jun 2005
    Location
    Houston, USA
    Posts
    349

    Default Re: rms class with stream function to exchange data with lin

    Well guys, here is the demon code so u won't have to download cy4th:

    Code:
    #!/bin/bash
    # E680i demon for java system access with cy4th
    # (c) 2005 by cytux
    
    # search for cyforth midlet dir and init variables:
    if [ -r /ezxlocal/gg.profile ]
      then 
      . /ezxlocal/gg.profile
    fi
    sleeptime=1
    searchpath="/bin/find /mmc/mmca1/.system/java/DownloadApps/"
    cy4thdir=$($searchpath -name 4th.jar -printf %h)
    cy4thcmd=$cy4thdir"/../rms/cy4thcmd.db"
    cy4thout=$cy4thdir"/cy4th.out"
    cy4therr=$cy4thdir"/cy4th.err"
    cy4thsts=$cy4thdir"/cy4th.sts"
    cy4thjar=$cy4thdir"/4th.jar"
    zip="/diska/.system/bin/zip"
    
    echo cy4thshelldemon started ...
    
    # enter main part
    
    while [ true ]
      do
      if [ -r $cy4thcmd ]
        then
        cy4thdo=$(/bin/grep cytux -a $cy4thcmd|/bin/sed s/cytux//)
        rm -f $cy4thout $cy4therr
        touch $cy4thout $cy4therr
        $cy4thdo >$cy4thout 2>$cy4therr
        rm -f $cy4thcmd
        /bin/grep rtc_time /proc/driver/rtc >$cy4thsts
        $zip -j $cy4thjar $cy4thout $cy4therr $cy4thsts
      fi
      sleep $sleeptime
    done
    echo cy4thshelldemon stopped ...
    % New UNIX password:
    > penis
    BAD PASSWORD: it's WAY too short
    % New UNIX password:

  4. #4

    Default Re: rms class with stream function to exchange data with lin

    hey cytax!
    i think i mentioned this problem before also... but the thing is ... when i create an RMS file from java.. i created "vginfo" but inside RMS directory it was saved as "vg%005info.db" so it added some stuff to it.. did it happen to u ?

    i mean cos when we are searching from linux side we would need the exact name ryt ?

    Also, when we write to the RMS from java i suppose it is stored in the RMS file ina fixed format.. how did u manage to read it from linux? simply opening the file and reading does the job ???
    the thing is that instead of that daemon u have i would be programming c++ code to read from RMS...so i just need to know if there is something i should care about or just opening the RMS file can do the job ?

    thanks
    -Mudassar

  5. #5
    Join Date
    Jun 2005
    Location
    Houston, USA
    Posts
    349

    Default Re: rms class with stream function to exchange data with lin

    U only have %xxx in the filename if u used special chars. vg_info or sumthing like this. vginfo should end with vginfo.db. If not, I don't know why not.

    From linux, yes it would be best with a known name but u may also search for filename parts.

    Yes RMS is written in a fixed format. It has a header and after this header there is a 1:1 block of the string. If u look at my technique, there i wrote my own code-"header" (cytux) top of the string and the demon searches it, throws it and takes the rest thereafter.

    U may use any language to open the file, search for the code-header (cytux or whatever) and use the block from thereafter. U mustn't use the rms-header.
    % New UNIX password:
    > penis
    BAD PASSWORD: it's WAY too short
    % New UNIX password:

  6. #6

    Default Re: rms class with stream function to exchange data with lin

    @mudassar
    I got the same f'd up characters when i tried to use some capital letters in the rms name as well, when i changed to all lower case everthing went fine.

  7. #7

    Default Re: rms class with stream function to exchange data with lin

    yup u r right.. i was using vg_info.. !! dummy me

    ok one more thing.. how do u write from linux daemon to res file ? i assume the resource file is bundled inside the jar file in the folder /res ... how do u access that file from linux side...? cos its inside the jar file...?

    thanks
    Mudassar

  8. #8

    Default Re: rms class with stream function to exchange data with lin

    we may want to confirm this w/ cytux, but it looks like his 4thshelldemon script creates cy4th.out, then zips this and stores the zipped file in MIDlet00XXX/Files where the loadres can read it. i am not sure why the jar file gets zipped, but AFAIK the loadres function doesn't care about the jar file at all, only the cytux.out file.

  9. #9

    Default Re: rms class with stream function to exchange data with lin

    ohhhh i c !!!!
    dude i hope there is a way to read the res file by just keeping it in the folder /Files... cos i dont know neway to zip the output file to MIDlet00XXX/Files through c++ ...

    so maybe Cytax can tell us if by simply putting the output file in "MIDlet00XXX/Files" is readable by loadres() ?

    thanks
    Mudassar

  10. #10

    Default Re: rms class with stream function to exchange data with lin

    i'm pretty ignorant about c/c++, but is there a way to execute a shell function from c++? and although i'd have to look more into the getResourceAsStream functionality, perhaps there is a way to read the file w/o zipping it.


 
+ Reply to Thread
Page 1 of 6 12345 ... LastLast

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2009, 06:40 PM
  2. cnn online video stream
    By bugmenot in forum -The Lounge-
    Replies: 0
    Last Post: 10-21-2006, 01:40 PM
  3. Video stream recording with linux
    By ycyas in forum Moto Media
    Replies: 3
    Last Post: 04-06-2006, 01:06 AM
  4. Cytux can u share RMS here?
    By mudassar in forum Development
    Replies: 1
    Last Post: 08-11-2005, 10:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Single Sign On provided by vBSSO

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1