#   Copyright (C) 2017 The YaCo Authors
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

#!/bin/bash
declare -a idcwords=(
    "__EA64__"
    "AddConstEx"
    "AddEnum"
    "AddSeg"
    "AddStrucEx"
    "AddStrucMember"
    "AnalyzeArea"
    "STRTYPE_C"
    "STRTYPE_LEN2"
    "STRTYPE_LEN4"
    "STRTYPE_PASCAL"
    "STRTYPE_TERMCHR"
    "STRTYPE_LEN2_16"
    "STRTYPE_LEN4_16"
    "STRTYPE_C_16"
    "AskYN"
    "BADADDR"
    "BeginTypeUpdating"
    "Comment"
    "DelConstEx"
    "DelFunction"
    "DelStrucMember"
    "Dfirst"
    "Dnext"
    "DOUNK_DELNAMES"
    "DOUNK_EXPAND"
    "DT_TYPE"
    "EndTypeUpdating"
    "Eval"
    "ExtLinA"
    "ExtLinB"
    "FF_ANYNAME"
    "FF_ASCI"
    "FF_BYTE"
    "FF_DATA"
    "FF_DOUBLE"
    "FF_DWRD"
    "FF_FLOAT"
    "FF_FUNC"
    "FF_LINE"
    "FF_OWRD"
    "FF_QWRD"
    "FF_WORD"
    "FirstSeg"
    "GetCharPrm"
    "GetConstBmask"
    "GetConstCmt"
    "GetConstEnum"
    "GetConstEx"
    "GetConstName"
    "GetConstValue"
    "GetEnum"
    "GetEnumCmt"
    "GetEnumFlag"
    "GetEnumIdx"
    "GetEnumName"
    "GetEnumQty"
    "GetEnumWidth"
    "GetFirstBmask"
    "GetFirstConst"
    "GetFirstMember"
    "GetFirstStrucIdx"
    "GetFlags"
    "GetFrameArgsSize"
    "GetFrameLvarSize"
    "GetFrameRegsSize"
    "GetFunctionFlags"
    "GetFunctionName"
    "GetFunctionName"
    "GetIdbPath"
    "GetInputFile"
    "GetLastMember"
    "GetManyBytes"
    "GetMarkComment"
    "GetMarkedPos"
    "GetMemberId"
    "GetMemberName"
    "GetMemberSize"
    "GetnEnum"
    "GetNextBmask"
    "GetNextConst"
    "GetNextStrucIdx"
    "GetOpnd"
    "GetSegmentAttr"
    "GetString"
    "GetStrucComment"
    "GetStrucId"
    "GetStrucName"
    "GetStrucNextOff"
    "GetStrucSize"
    "GetTrueNameEx"
    "GetType"
    "hasUserName"
    "INF_AUTO"
    "INF_STRTYPE"
    "isASCII"
    "IsBitfield"
    "isCode"
    "isEnum0"
    "isEnum1"
    "isLoaded"
    "isStroff0"
    "isStroff1"
    "isStruct"
    "IsUnion"
    "ItemSize"
    "LineA"
    "LineB"
    "MakeCode"
    "MakeComm"
    "MakeData"
    "MakeFrame"
    "MakeFunction"
    "MakeRptCmt"
    "MakeStr"
    "MakeUnkn"
    "MarkPosition"
    "MS_0TYPE"
    "Name"
    "NextSeg"
    "PrevHead"
    "PrevNotTail"
    "REF_OFF32"
    "Refresh"
    "Rfirst"
    "Rfirst0"
    "Rnext"
    "RNext"
    "Rnext0"
    "RptCmt"
    "SEGATTR_ALIGN"
    "SEGATTR_BITNESS"
    "SEGATTR_COLOR"
    "SEGATTR_COMB"
    "SEGATTR_END"
    "SEGATTR_FLAG"
    "SEGATTR_ORGBASE"
    "SEGATTR_PERM"
    "SEGATTR_SEL"
    "SEGATTR_START"
    "SEGATTR_TYPE"
    "SegEnd"
    "SegName"
    "SegStart"
    "SetCharPrm"
    "SetConstCmt"
    "SetConstName"
    "SetEnumBf"
    "SetEnumCmt"
    "SetEnumWidth"
    "SetFlags"
    "SetFunctionCmt"
    "SetFunctionFlags"
    "SetMemberComment"
    "SetMemberComment"
    "SetMemberName"
    "SetMemberType"
    "SetSegmentAttr"
    "SetStrucComment"
    "SetStrucmember"
    "SetType"
    "UTP_STRUCT"
    "Wait"
    )
declare -a idaapiwords=(
    "isOff"
    "NT_LOCAL"
    "SN_AUTO"
    "SN_CHECK"
    "SN_LOCAL"
    "SN_NOCHECK"
    "SN_NOLIST"
    "SN_NON_AUTO"
    "SN_NON_PUBLIC"
    "SN_NON_WEAK"
    "SN_NOWARN"
    "SN_PUBLIC"
    "SN_WEAK"
    )
for word in "${idcwords[@]}"
do
    sed -i "s/ $word/ idc.$word/" "$1"
    sed -i "s/($word/(idc.$word/" "$1"
    sed -i "s/=$word/=idc.$word/" "$1"
done
for word in "${idaapiwords[@]}"
do
    sed -i "s/ $word/ idaapi.$word/" "$1"
    sed -i "s/($word/(idaapi.$word/" "$1"
    sed -i "s/=$word/=idaapi.$word/" "$1"
done

sed -i "s/!= None/is not None/" "$1"
sed -i "s/== None/is None/" "$1"
