LCOV - code coverage report
Current view: top level - media/libstagefright/frameworks/av/media/libstagefright/foundation - hexdump.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 32 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2010 The Android Open Source Project
       3             :  *
       4             :  * Licensed under the Apache License, Version 2.0 (the "License");
       5             :  * you may not use this file except in compliance with the License.
       6             :  * You may obtain a copy of the License at
       7             :  *
       8             :  *      http://www.apache.org/licenses/LICENSE-2.0
       9             :  *
      10             :  * Unless required by applicable law or agreed to in writing, software
      11             :  * distributed under the License is distributed on an "AS IS" BASIS,
      12             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13             :  * See the License for the specific language governing permissions and
      14             :  * limitations under the License.
      15             :  */
      16             : 
      17             : //#define LOG_NDEBUG 0
      18             : #undef LOG_TAG
      19             : #define LOG_TAG "hexdump"
      20             : #include <utils/Log.h>
      21             : 
      22             : #include "hexdump.h"
      23             : 
      24             : #include "ADebug.h"
      25             : #include "AString.h"
      26             : 
      27             : #include <ctype.h>
      28             : #include <stdint.h>
      29             : #include <stdio.h>
      30             : 
      31             : namespace stagefright {
      32             : 
      33           0 : static void appendIndent(AString *s, int32_t indent) {
      34             :     static const char kWhitespace[] =
      35             :         "                                        "
      36             :         "                                        ";
      37             : 
      38           0 :     CHECK_LT((size_t)indent, sizeof(kWhitespace));
      39             : 
      40           0 :     s->append(kWhitespace, indent);
      41           0 : }
      42             : 
      43           0 : void hexdump(const void *_data, size_t size, size_t indent, AString *appendTo) {
      44           0 :     const uint8_t *data = (const uint8_t *)_data;
      45             : 
      46           0 :     size_t offset = 0;
      47           0 :     while (offset < size) {
      48           0 :         AString line;
      49             : 
      50           0 :         appendIndent(&line, indent);
      51             : 
      52             :         char tmp[32];
      53           0 :         sprintf(tmp, "%08lx:  ", (unsigned long)offset);
      54             : 
      55           0 :         line.append(tmp);
      56             : 
      57           0 :         for (size_t i = 0; i < 16; ++i) {
      58           0 :             if (i == 8) {
      59           0 :                 line.append(' ');
      60             :             }
      61           0 :             if (offset + i >= size) {
      62           0 :                 line.append("   ");
      63             :             } else {
      64           0 :                 sprintf(tmp, "%02x ", data[offset + i]);
      65           0 :                 line.append(tmp);
      66             :             }
      67             :         }
      68             : 
      69           0 :         line.append(' ');
      70             : 
      71           0 :         for (size_t i = 0; i < 16; ++i) {
      72           0 :             if (offset + i >= size) {
      73           0 :                 break;
      74             :             }
      75             : 
      76           0 :             if (isprint(data[offset + i])) {
      77           0 :                 line.append((char)data[offset + i]);
      78             :             } else {
      79           0 :                 line.append('.');
      80             :             }
      81             :         }
      82             : 
      83           0 :         if (appendTo != NULL) {
      84           0 :             appendTo->append(line);
      85           0 :             appendTo->append("\n");
      86             :         } else {
      87           0 :             ALOGI("%s", line.c_str());
      88             :         }
      89             : 
      90           0 :         offset += 16;
      91             :     }
      92           0 : }
      93             : 
      94             : }  // namespace stagefright
      95             : 
      96             : #undef LOG_TAG

Generated by: LCOV version 1.13