1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WinSCard.ini から Keys.cpp を生成するなどを考えてみる

Posted at

WinSCard.ini を Keys.cpp のフォーマットに成形して出力するだけのシェルスクリプトを考えてみました。ファイル出力はリダイレクトなどで良いんじゃないでしょうか?

使い方
WSCard2kcpp.sh [入力ファイル]

WSCard2kcpp.sh
#!/bin/sh

FILE=$1

# ファイルのゴミ取り
  fload() {
    sed 's/[^ -~0-9a-Z=#]//g' ${FILE}
  }

# 配列にデータを格納
  IFS=$'\n'
  BID=($( fload | grep 'BID' | sed -e 's/.*BID[ =:]*\([[0-9a-fA-F]\{2\}\)/\1/g'))
  SID=($( fload | grep '\[.*\]' | sed -e 's/\[\(.*\)\]/\1/g'))
  NID=($( fload | grep '\[.*\]' | sed -e 's/\[\(.*\)\]/\1/g' | sed -e 's/Star Channel HD/StarChannelHD/g' -e 's/SkyPerfecTV E2 \/ 110CS/E2_110CS/g' -e 's/Safenet/Safetynet/g'))
  KW0=($( fload | grep 'KW0' | sed -e 's/.*KW0[ =:]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*/0x\1, 0x\2, 0x\3, 0x\4, 0x\5, 0x\6, 0x\7, 0x\8, 0x\9,/g'))
  KW1=($( fload | grep 'KW1' | sed -e 's/.*KW1[ =:]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*\([0-9a-fA-F]\{2\}\)[ ,]*/0x\1, 0x\2, 0x\3, 0x\4, 0x\5, 0x\6, 0x\7, 0x\8, 0x\9,/g'))

# includeファイル定義
  echo -e "#include \"Global.h\"\n#include \"Keys.h\"\n#include \"Keyset.h\"\n"

# Keysetブロックの配列出力
  for ((i = 0; i < ${#BID[@]}; i++)); do
    echo -e "static const Keyset_t Keyset_${NID[i]} = {\n\t0x${BID[i]},\n\t// keys\n\t${KW0[i]}\n\t${KW1[i]}\n\t\"${SID[i]}\",\n};\n"
  done

# フッターブロックの配列出力
  echo -e "s32\nBCAS::Keys::RegisterAll (void)\n{"
  for ((i = 0; i < ${#NID[@]}; i++)); do
    echo -e "\tBCAS::Keyset::Register (&Keyset_${NID[i]});"
  done
  echo -e "\n\treturn 0;\n}"
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?