PasjaGSM.pl
  Jesteś w: Forum > [Trix] Porady dla początkujących...


[Trix] Porady dla początkujących...

Forum.PasjaGSM.pl » ...:Sprzęt:... » Nokia » DCT-4 » [DCT4] Modyfikacje HW i SW » [Trix] Porady dla początkujących...
Poprzedni temat «» Następny temat
Autor Wiadomość
 
riger 
Expert
Elektronik...



Telefon: 5200
Operator: Orange
Pomógł: 25 razy
Wiek: 26
Dołączył: 26 Lut 2005
Posty: 1483
Skąd: 50km do Gdanska
Wysłany: 2006-07-24, 00:05   [Trix] Porady dla początkujących...

G3gg0 wydal poradnik na temat pisania skryptow dla Trix'a dla poczatkujacych. (Jak mi sie bedzie chcialo to przeloze na PL :p) Narazie proste skrypty. Oto cytat:
g3gg0 napisał/a:
minimal script:
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    say ( "hello world" );
    return E_OK;
}


dump the byte at address 0x00000000.
requires a loaded file (e.g. simple mode input file)
if that address is invalid, a 0xCC is returned
(reading from invalid adresses cause a 0xCC to be returned)
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    say ( "byte: 0x%02X\n", GetByte(0) );
    return E_OK;
}

Change the byte at address 0x00000005 to 0xFF
requires a loaded file (e.g. simple mode input file)
if that address is invalid, a 0xCC is returned.
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    say ( "byte: 0x%02X\n", GetByte(5) );
    SetByte(5, 0xFF) );
    say ( "byte: 0x%02X\n", GetByte(5) );
    return E_OK;
}

dump the WORD at address 0x00000000.
requires a loaded file (e.g. simple mode input file)
if that address is invalid, a 0xCCCCCCCC is returned
(reading from invalid adresses cause a 0xCCCCCCCC to be returned)
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    say ( "word: 0x%08X\n", GetWord(0) );
    return E_OK;
}

overwrite data at pos 0x00000010 with the word "HELLO"
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    char *buffer = "HELLO";

    MemCpyPut ( 0x10, buffer, strlen ( buffer ) );
    return E_OK;
}

read 15 data bytes at pos 0x00000010 into a malloc'ed buffer.

Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    char *buffer = NULL;

    buffer = malloc ( 15 );

    MemCpyGet ( buffer, 0x10, 15 );
    return E_OK;
}

search for the pattern "HELLO" in the whole loaded file and print its address.
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    int pos = 0;

    pos = SimpleFindPattern (  "HELLO", "\xff\xff\xff\xff\xff", 5, 0 /* options - leave zeroed */ );
    if ( pos == E_FAIL )
        say ( "not found!\n" );
    else
        say ( "found at 0x%08X\n", pos );
    return E_OK;
}

search for the pattern "HELLO" in the loaded file between address 0x10 and 0x80
and print its address.
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    int pos = 0;

    pos = QuickFindPattern (  "HELLO", "\xff\xff\xff\xff\xff", 5, 0x10, 0x80, 0 /* options - leave zeroed */ );
    if ( pos == E_FAIL )
        say ( "not found!\n" );
    else
        say ( "found at 0x%08X\n", pos );
    return E_OK;
}


I cos dla bardziej wtajemniczonych:

g3gg0 napisał/a:

load a file manually and print the string at requested address.
you dont need to load the file in the trix gui.

NOTE: there's no SetWorkspace() function yet, sorry forgot that one
for now just use the internal variable 'trix_workspace'

trix_workspace is the internal variable, in which normally the
files would get loaded by the GUI (or cmdline tool) in the way
we see it here, but we may change it in our script.
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    char *filename = NULL;
    int start = 0;

    if ( UiDlgString ( "What file to open?", &filename ) == E_FAIL || (strlen ( filename ) <= 0 ) )
        return E_OK;

    start = UiDlgInt ( "At which address should i start do dump?  (0-1024)", 0, 1024 );
    if ( start == E_FAIL )
        return E_OK;

    if ( UiDlgBool ( "Start now?" ) == E_FAIL )
        return E_OK;


    trix_workspace = WorkspaceStartup ( filename );
   
    if ( GetWorkspace() == NULL )
    {
        say ( "loading failed\n" );
        return E_FAIL;
    }

    say ( "String at pos %i (%i bytes):\n%s\n", start, GetStrLen ( start ), GetStr ( start ) );
   
    return E_OK;
}

load a file manually and write it back as a bz2-compressed file.

NOTE: __file_format() and __file_write() are still internal functions...
they will soon get named FileFormat() and FileWrite()
that will happen somewhen during the beta phase.

also there's no SetWorkspace() function yet, sorry forgot that one
for now just use the internal variable 'trix_workspace'
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    char *filename_in = NULL;
    char *filename_out = NULL;

    if ( UiDlgString ( "What file to open? (e.g. flash.fls)", &filename_in ) == E_FAIL || (strlen ( filename_in ) <= 0 ) )
        return E_OK;
    if ( UiDlgString ( "What name for output file? (e.g. flash.fls.bz2)", &filename_out ) == E_FAIL || (strlen ( filename_out ) <= 0 ) )
        return E_OK;


    trix_workspace = WorkspaceStartup ( filename_in );
   
    if ( GetWorkspace() == NULL )
    {
        say ( "loading failed\n" );
        return E_FAIL;
    }

    if ( __file_format ( GetWorkspace()->fileinfo, "BZ2" ) != E_OK )
    {
        say ( "compressing failed\n" );
        return E_FAIL;
    }

    if ( __file_write ( filename_out, GetWorkspace()->fileinfo ) != E_OK )
    {
        say ( "writing failed\n" );
        return E_FAIL;
    }

    say ( "writing done\n" );
   
   
    return E_OK;
}

the same bz2 compression, but just using the files we selected as
input and output files in the GUI.

NOTE: __file_format() is still an internal function...
it will soon get named FileFormat()
that will happen somewhen during the beta phase.
Kod:
#include trix
#include stdio
#include stdlib

int main()
{
    if ( GetWorkspace() == NULL || GetWorkspace()->fileinfo == NULL )
    {
        say ( "no file opened, please select one in GUI (also set output file)\n" );
        return E_FAIL;
    }

    if ( __file_format ( GetWorkspace()->fileinfo, "BZ2" ) != E_OK )
    {
        say ( "compressing failed\n" );
        return E_FAIL;
    }


    say ( "compression done\n" );
   
   
    return E_OK;
}
^
 
 
     
Wyświetl posty z ostatnich:   
Odpowiedz do tematu
Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Nie możesz załączać plików na tym forum
Możesz ściągać załączniki na tym forum
Dodaj temat do Ulubionych
Wersja do druku

Skocz do: