Blog

  • How to reset cisco device

    2023-12-28 15:48:51.545349

     

    Method one
    • en
    • write erase
    • reload
    Method two
    • Detach all cables
    • Hold power or mode button until a light start flashing
    • Release the button
    Method three
    • Attach console
    • Power on device
    • Wait for hash marks (#)
    • Press ESC  
    • flash_init
    • <wait for boot to finish>
    • rename flash:config.txt flash:config.old
    • reset
    • <wait for boot to finish>
    • del flash.config.old


  • openssl tips

    2023-12-28 15:48:39.835202

     

    Use openssl to encrypt/decrypt file


    openssl aes-256-cbc -salt -in secrets.txt -out secrets.txt.enc
    openssl aes-256-cbc -d -in secrets.txt.enc -out secrets.txt.new
    

    * You will be prompted for a password.

    Use openssl to generate self-signed cert 

    openssl req -x509 -newkey rsa:1024 -keyout file.pem -out file.crt -days 9999 -nodes

    or advanced method

    openssl genrsa -out server.key 1024
    openssl req -new -key server.key -out server.csr \
           -subj '/C=RU/ST=St.Petersburg/L=St.Petersburg/CN=www.4foo.net'
     
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    

    make sure you enter right value to CN field

    to display cert details

    openssl x509 -in cert.pem -noout -text


  • jar like container in python

    2023-12-28 15:48:26.268246

    One of common question of python programming is how to do jar equivalent - i.e. run something like python myapp.zip . Below I describe a method producing a close result (hey python team - good place to enhance): unfortunately couple of bugs in python zip handling (e.g. python can't import module from zipfile with comments) make this task a little bit tricky.

    1. Make sure you app is ready to work with zip bundle i.e. file is replaced to ZipFile when necessary.
    1. Prepare the entry point:
      main.py
      def __main__():
           ....
      
    1. create a bundle
      zip -r test.zip *.py *.pyc
      
    1. create a launcher either shell or pure python one and place it somewhere.
    #!/bin/sh
    mod="$1"
    shift
    python -c "import sys; sys.path.insert(0,'${mod}'); import main;main.__main__()" $*
    
    import sys
    sys.path.insert(0,sys.argv[1])
    import main
    main.__main__()

    enjoy

     


  • How to open java coredump in gdb

    2023-12-28 15:47:57.094437

    After dozen of experiments I finally come to next action sequence with gdb as the most universal/reliable one.

    Good case we have access to client libraries

    1. Check gdb version. it should be 6.x the later the better.
    2. Create directory D inside you working one
    3. Create D/gdbrc file with *full* path to your directory
      set solib-absolute-prefix /home/dms/Sept12/12_09_2008_20_00_node4/D 
      

      Notice: set substitute-path doesn't work because gdb apply it to source files only

    4. symlink apropriate D/java
    5. run
         gdb -x D/gdbrc D/java core
      
    6. type
          info shared
      

    You will see something like:

    (gdb) info shared
    From        To          Syms Read   Shared Object Library
                            No          /lib/tls/libpthread.so.0
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    0x00a05bb0  0x00a068c4  Yes /home/dms/Sept12/D/lib/libdl.so.2
    ...
    0x008c9c00  0x009b9800  Yes /home/dms/Sept12/D/lib/tls/libc.so.6
                            No          /lib/libnsl.so.1
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    1. leave gdb and copy or link missed library under D.

    In my case:

    D/lib/tls/lib/tls/libpthread.so.0
    D/lib/libnsl.so.1
    
    

    To gather all libraries necessary to open a coredump on other machine run:

     gdb -batch --eval "info shared"  D/java core 2> /dev/null |\
     sed -n -e 's/^.*Yes[^\/]*\//\//p' -e 's/^.*No[^\/]*\//\//p'  > filelist
    

    on your own machine and than:

     cat filelist | zip zipme.zip -@
    

    on client one

    Bad case - we don't have access to original libraries. We still can restore JVM part of stack trace manually.

    To do it:

    1. Run some java app (e.g. Java2Demo.jar) with exactly the same version of jdk and JVM part of command line.
    2. Kill it by kill -BUS to get a core.
    3. Open core with gdb and check whether upper part of stack trace match customer's one -
    #0  0xffffe424 in __kernel_vsyscall ()
    #1  0xb76f96e0 in raise () from /lib/libc.so.6
    #2  0xb76faf15 in abort () from /lib/libc.so.6
    #3  0xb70abbaf in os::abort(bool)
    #4  0xb71de555 in VMError::report_and_die()
    #5  0xb70b257c in JVM_handle_linux_signal ()
    #6  0xb70ae7a4 in signalHandler(int, siginfo*, void*) ()
    #7  <signal handler called>
    

    Ever without symbols - you should have exactly 6 entries before <> and os::abort is right the next after libc abort.

    • Type info shared and get addresses where jvm is loaded:
      0xb6bf2bd0  0xb71fe250  Yes (*)  /opt/jdk1.6.0_18/jre/lib/i386/server/libjvm.so
      
    • Calculate offset of os:abort : 0xb70abbaf - 0xb6bf2bd0 = 0x4b8fdf
    • Calculate jvm size: 0xb71fe250 - 0xb6bf2bd0 = 0x60b680
    • Go to cu core and calculate jvm start and end addresses
      <os::abort> - 0x4b8fdf = N, N + 0x60b680
      

    *Calculate offset between your JVM and cu JVM

      <os::abort> - 0xb70abbaf (os:abort from my core, or compare two JVM starts)
    
    • Get stacktrace offset, check whether it within range. apply difference
    • Go to your coredump and type
    info address <recalcualted_address>
    


  • Thinkpad 420 WiFi and Bluetooth issue

    2023-12-28 15:44:32.134245

    If you installed windows 10 on old Thinkpad T420 and you realize that neither bluetooth nor wifi are working properly (windows reports that it is turned off and can't turn it on) >do following:

    • 1. Make sure that small switch located on the right side of laptop right after the CD bay is turned on (green is shown, knob is under computer icon)
    • 2. Make sure that wifi and bluetooth access is enabled in the BIOS, check Security::I/O Ports section.
    • 3. Make sure that Fn and CRL buttons is not swapped in BISO, check Config::Keyboard section
    • 4. Go to the Device Manager and check that Intel Centrino adapter is present, update it's driver  - let autoupdate find appropriate one
    • 5. Install  Thinkpad Hotkey Features Integration software from http://support.lenovo.com including all aditional utilities, like on-screen menu
    • 6. Reboot you PC
    • 7. Press Fn + F5 and enable Bluetooth and WiFi

    You should be able to use WiFi/Bluetooth now.


  • How to extract Mac OS xip archive

    2023-12-28 15:44:09.390468

    xip is an old archive format used to distribute XCode.  it's actually an xar format but with ability to be signed. If you installing the same software multiple times and don't want to spend time to verify known to be valid signature, instead of xip -x do the following (you can use xar -x -f instead of bsdtar xvf):

    bsdtar xvf Archive.xip

    ditto -x Content .

     

     


  • Executing jcmd programmatically

    2023-12-28 15:43:56.405177

    It's often convenient to run jcmd command programmatically from within a testcase to get some information or to adjust options.

    See the template below:

    // import javax.management.ObjectName;
    // import javax.management.MBeanServer;
    
     public static void reloadCompilerDirectives(String filename) {
        String result;
        result = doRunDcmd("compilerDirectivesClear", new String[]{""});
        result = doRunDcmd("compilerDirectivesAdd", new String[]{ filename });
      }
    
      private static String doRunDcmd(String operationName, String operationArgs[]) {
          ObjectName objectName = 
              new ObjectName("com.sun.management:type=DiagnosticCommand");
          MBeanServer mbeanServer = 
              ManagementFactory.getPlatformMBeanServer();
          Object[] params = new Object[] { operationArgs };
          String[] signature = new String[]{ String[].class.getName() };
          return(String) mbeanServer.invoke(objectName, operationName, params, signature);
      }
    
    
    
    


  • Print the code emitted by Hotspot assembler

    2023-12-28 15:43:47.352285

    It's not always obvious what assembly will be generated after expanding all the macros of the HotSpot meta-assembly system. The following code shows how to print the actual code generated by HotSpot.

    // #define DMS_DEBUG
    #ifdef DMS_DEBUG
    address barrier_start = masm->code()->insts_end();
    #endif
     __ block_comment("nmethod_barrier begin");
     __ ldr_label(tmp0, guard);
    ...
     __ bind(skip);
     __ block_comment("nmethod_barrier end"); 
    
    #ifdef DMS_DEBUG 
    address barrier_end = masm->code()->insts_end(); 
    tty->print_cr("DMS: barier %p %p bytes: %d", barrier_start, barrier_end, barrier_end - barrier_start); 
    
    //  masm->code()->print(); 
    masm->code()->decode(); 
    #endif
    
    


  • Conditional Syslog from within the HotSpot

    2023-12-28 15:43:35.110007

    The following code shows how to organize debug printing with minimal impact on the loaded system

    #include <syslog.h>
    #include <stdarg.h>
    #include <stdlib.h>
    
    static void print_at(const char *srcfile, int line, const char *format, ...) {
      va_list ap;
      const char *envvar="JAVA_SHOULD_PRINT_AT";
      static int requested_line = -1;
    
      if (requested_line == -1) {
        const char *should_print = getenv(envvar);
        requested_line = (should_print != NULL) ? atoi(should_print) : 0;
        openlog("javadebug", LOG_PID, LOG_UUCP);
      }
    
      if (requested_line == line) {
         va_start(ap, format);
         vsyslog(LOG_DEBUG, format, ap);
         va_end(ap);
      }
    }
    


  • ffmpeg tips

    2023-12-28 15:37:08.077720

     

    dv => mpeg2 

    dvgrab capture_20060604.dv
    ffmpeg -i capture_20060604.dv  -target pal-dvd capture_20060604.mpeg
    

    more ... http://womble.decadent.org.uk/talks/dvd-ukuug06/dvd-talk-ukuug06-paper.html

    mkv => avi: change container 

    /opt/mplayer/bin/mencoder infile.mkv -oac copy -ovc copy -o outfile.avi
    

    or using mkvtoolnix

    1. MKV is a container, to see what the file contains:
    $ mkvinfo movie.mkv
    
    |+ Segment tracks
    | + Track number: 1
    ^^^^^^^^^^^^^^^
    + Track type: video
    ^^^^^^^^^^^^^^^^
    
    1. select the numbers of the trucks you want to extract and type:
      $ mkvextract tracks "/mnt/common/Film/movie.mkv" 1:/mnt/common/Film/video.h264 2:/mnt/common/Film/audio.aac
      
    1. Let's put all toghether:
    $ mencoder -audiofile video.aac -oac copy -ovc copy audio.h264 [-of mpeg]  -o movie_complete.mpg
    

    or

    $ ffmpeg -i video.h264 -i audio.aac -map 0.0:0 -map 1.0:0 -acodec copy -vcodec copy -r 23.976 -f vob video.mpg