All source files added

This commit is contained in:
AndyWhittaker 2018-01-22 17:22:57 +00:00
parent 3e2ff13e2a
commit 5610857438
24 changed files with 7520 additions and 0 deletions

868
BoschHelper.cpp Normal file
View File

@ -0,0 +1,868 @@
// BoschHelper.cpp: implementation of the BoschHelper class.
//
//////////////////////////////////////////////////////////////////////
//Standard Defs
typedef int BOOL;
#define FALSE 0
#define TRUE 1
#define NULL 0
#include <ida.hpp>
#include <idp.hpp>//str2reg()
#include <expr.hpp>
#include <bytes.hpp>
#include <loader.hpp>
#include <kernwin.hpp>
#include <name.hpp>
#include <offset.hpp>
#include <search.hpp>
#include <srarea.hpp> //SetDefaultRegisterValue()
#include <allins.hpp> // processor instructions
#include <funcs.hpp> //get_func()
#include <enum.hpp> //for enumerations
#include <auto.hpp> // for showaddr
#include "BoschHelper.h"
//#include "FunctionSigs.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
BoschHelper::BoschHelper()
{
mSelector = 1;
}
BoschHelper::~BoschHelper()
{
}
//////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////
// Loops through the binary and makes disassembled code
bool BoschHelper::CreateDissCode(ea_t eaStartAddr, ea_t eaEndAddr)
{
msg("Creating disassembly from 0x%x through to 0x%x\n", eaStartAddr, eaEndAddr);
ea_t eaAddr, eaLenOfGeneratedCode;
int iCount, iReturns;
ushort uWord;
eaAddr = eaStartAddr;
eaLenOfGeneratedCode = 1;
iCount = iReturns = 1;
show_wait_box("Creating disassembly...");
for (eaAddr; eaAddr<eaEndAddr; eaAddr += eaLenOfGeneratedCode)
{
if ((eaAddr % 0x1000) == 0)
{
showAddr(eaAddr);
if (wasBreak())
break;
}
//guard against disassembling 0xffff or 0x0000 pairs
uWord = static_cast<ushort>(get_16bit(eaAddr));//read the word at the current location
if(uWord == 0xffff)
{
// msg("0xffff read at 0x%x\n", eaAddr);
doWord(eaAddr, 4);//Convert to data word
eaAddr+=1;//skip these bytes
}
else if(uWord == 0x0000)
{
// msg("0x0000 read at 0x%x\n", eaAddr);
doWord(eaAddr, 4);//Convert to data word
eaAddr+=1;//skip these bytes
}
else if(uWord == 0x8000)
{
// msg("0x8000 read at 0x%x\n", eaAddr);
doWord(eaAddr, 4);//Convert to data word
eaAddr+=1;//skip these bytes
}
else
{
//attempt to disassemble the next code
eaLenOfGeneratedCode = create_insn(eaAddr);//create the disassembled code and return the length of it
//msg("Code created at 0x%X\n", eaAddr);
if(eaLenOfGeneratedCode == 0)
{//guard against nothing happening
eaLenOfGeneratedCode++;
}
else if(iCount >= 0x200)
{
iCount=0;
msg(".");
}
else if(iReturns >= 0x4000)
{
iReturns=0;
msg("\n");
}
}
}
msg("\n");
hide_wait_box();
msg("Looking through code to make subroutines....\n");
//
// Look for subroutines within the code
//
eaAddr = eaStartAddr;
eaLenOfGeneratedCode = 1;
iCount = iReturns = 1;
// Instructions we know that subroutines don't start with.
int instrs[] = { C166_jmps, C166_jmpr, C166_ret, C166_reti, C166_retp, C166_rets, C166_rol, C166_add, C166_shr, C166_xor, C166_xorb, 0 };
char mnem[MAXSTR];
const char *res;
bool bFound;
show_wait_box("Making subroutines...");
for (eaAddr; eaAddr<eaEndAddr;)
{
if ((eaAddr % 0x100) == 0)
{
showAddr(eaAddr);
if (wasBreak())
break;
}
//Create a function if possible but ignore certain instructions
//because we know functions will not start with them
bFound = false;
//Get the mnemonic at this address
res = ua_mnem(eaAddr, mnem, sizeof(mnem)-1);
// Check the mnemonic of this address against all
// mnemonics we're interested in.
for (int i = 0; instrs[i] != 0; i++)
{
if (cmd.itype == instrs[i])
{
bFound = true;
}
}
if(!bFound)
{
if(add_func(eaAddr, BADADDR))
{
msg("Function created at %x\n", eaAddr);
func_t *func = get_func(eaAddr);
if (func != NULL)
{
eaAddr += (func->endEA - func->startEA);
}
else
{
eaAddr++;
}
}
else
{
eaAddr++;
}
}
else
{
eaAddr++;
}
}
hide_wait_box();
return true;
}
// Loops through the binary and searches for where DTC flags are being set.
bool BoschHelper::EnumDTCflags(ea_t eaStartAddr, ea_t eaEndAddr)
{
msg("Searching for DTC setting flags from 0x%x through to 0x%x\n", eaStartAddr, eaEndAddr);
// Instructions we know that DTC setting is done by.
char mnem[MAXSTR];
const char *res;
// uval_t uvalOp1Value, uvalOp2Value;
ea_t eaAddr;
eaAddr = eaStartAddr;// sets the start
show_wait_box("Searching for DTCs...");
for (eaAddr; eaAddr<eaEndAddr;)
{
if ((eaAddr % 0x100) == 0)
{
showAddr(eaAddr);
if (wasBreak())
break;
}
// Get the flags for this address
flags_t flags = getFlags(eaAddr);
// Only look at the address if it's a head byte, i.e.
// the start of an instruction and is code.
if (isHead(flags) && isCode(flags))
{
//char mnem[MAXSTR];
//Get the mnemonic at this address
res = ua_mnem(eaAddr, mnem, sizeof(mnem)-1);
// Check the mnemonic of this address against all
// mnemonics we're interested in.
if(cmd.itype == C166_bfldh)//We've found the instruction we're interested in.
{
msg("bfldh found at 0x%x\n", eaAddr);
//we've found the instruction we're interested in.
//get_operand_immvals(eaAddr, 1, &uvalOp1Value);
//get_operand_immvals(eaAddr, 2, &uvalOp2Value);
//msg("Instruction Len 0x%x : Op1 Value 0x%x : Op2 Value 0x%x\n", cmd.size, uvalOp1Value, uvalOp2Value);
op_enum(eaAddr, 1, get_enum("DTCHBit"), NULL);
eaAddr+= cmd.size;//next instruction
}
else if(cmd.itype == C166_bfldl)//We've found the instruction we're interested in.
{
msg("bfldl found at 0x%x\n", eaAddr);
//we've found the instruction we're interested in.
//get_operand_immvals(eaAddr, 1, &uvalOp1Value);
//get_operand_immvals(eaAddr, 2, &uvalOp2Value);
op_enum(eaAddr, 1, get_enum("DTCLBit"), NULL);
eaAddr+= cmd.size;//next instruction
}
else
eaAddr++;
}
else
eaAddr++;
}
hide_wait_box();
return 1;
}
// Sets the default register values on the C16x CPU
bool BoschHelper::SetC16xRegs(const char *szRegName, sel_t value)
{
int iReg;
iReg = str2reg(szRegName);
msg("Setting register %s, number %i to %x", szRegName, iReg, value);
if (set_default_segreg_value(nullptr, iReg, value))
msg(" successful.\n");
else
{
msg(" failed.\n");
return 0;
}
return 1;
}
// Creates a Bosch segment and default registers
bool BoschHelper::CreateC16xSmallBoschSegments(ea_t eaStartAddr, ea_t eaEndAddr, char* cName, const char *sclass, sel_t dpp0, sel_t dpp1, sel_t dpp2, sel_t dpp3)
{
char cBuf[20];
ea_t eaParagraph;
msg("\nBoschHelper::CreateC16xSmallBoschSegments Started\n");
// msg("Deleting Segments\n");
// del_segm(eaStartAddr, SEGDEL_KEEP);
::qsnprintf(cBuf, 17, "%s", cName);
eaParagraph = eaStartAddr >> 4;// divide by 16
msg("Creating segment at para %x, start address %x, end address %x, name %s, selector 0x%x\n", eaParagraph, eaStartAddr, eaEndAddr, cBuf, mSelector);
set_selector(mSelector, eaParagraph);
// set_selector(mSelector, 0);
mSelector++;
msg("Adding new segments\n");
add_segm(eaParagraph, eaStartAddr, eaEndAddr, cBuf, sclass);
//Set the default register values for this segment
msg("Setting DPPs\n");
SetC16xRegs("dpp0", dpp0);
SetC16xRegs("dpp1", dpp1);
SetC16xRegs("dpp2", dpp2);
SetC16xRegs("dpp3", dpp3);
msg("BoschHelper::CreateC16xSmallBoschSegments Finished\n");
return 1;
}
// Creates the correct Bosch segments and default registers
bool BoschHelper::CreateC16xBoschSegments(ea_t eaParagraph, unsigned int iNumSegsToCreate, const char *sclass, sel_t dpp0, sel_t dpp1, sel_t dpp2, sel_t dpp3)
{
sel_t selSelector = 0;
ea_t eaStartAddr, eaEndAddr;
int iDPPNum;
char cBuf[20];
msg("\nBoschHelper::CreateC16xBoschSegments Started\n");
for(selSelector; selSelector<iNumSegsToCreate; selSelector++)
{
eaStartAddr = (eaParagraph * 0x10) + (selSelector * 0x4000);
eaEndAddr = eaStartAddr + 0x4000;
iDPPNum = eaStartAddr / 0x4000;//gets the dpp equivalent for the segment label
qsnprintf(cBuf, 17, "Seg0x%x@%x", iDPPNum, eaStartAddr);
msg("Creating segment at para %x, start address %x, end address %x, name %s, selector 0x%x\n", eaParagraph, eaStartAddr, eaEndAddr, cBuf, mSelector);
set_selector(mSelector, eaParagraph);
// set_selector(mSelector, 0);
mSelector++;
add_segm(eaParagraph, eaStartAddr, eaEndAddr, cBuf, sclass);
//Set the default register values for this segment
msg("Setting DPPs\n");
SetC16xRegs("dpp0", dpp0);
SetC16xRegs("dpp1", dpp1);
SetC16xRegs("dpp2", dpp2);
SetC16xRegs("dpp3", dpp3);
}
msg("BoschHelper::CreateC16xBoschSegments Finished\n");
return 1;
}
// Loops through the binary and tries to make code offsets from arrays
// e.g. movb [r5+0E0A4h], rl4 = movb [r5+word_E0A4], rl4
bool BoschHelper::FindAndCreateArrayOffsets(ea_t eaStartAddr, ea_t eaEndAddr)
{
msg("Finding array offsets and trying to create them from 0x%x through to 0x%x\n", eaStartAddr, eaEndAddr);
ea_t eaAddr, eaLenOfGeneratedCode;
int iCount, iReturns;
//
// Look for known function that will contain offsets within the code
//
eaAddr = eaStartAddr;
eaLenOfGeneratedCode = 1;
iCount = iReturns = 1;
// Instructions we know that contain arrays.
int instrs[] = { C166_mov, C166_movb, 0 };
char mnem[MAXSTR];
const char *res;
bool bFound;
show_wait_box("Searching for array offsets...");
for (eaAddr; eaAddr<eaEndAddr;)
{
//Find instructions we know will have offsets in them
bFound = 0;
if ((eaAddr % 0x100) == 0)
{
showAddr(eaAddr);
if (wasBreak())
break;
}
//Get the flags for this address
flags_t flags = getFlags(eaAddr);
//Only look at the address if it's a head byte
//i.e. the start of an instruction and its code
if(isHead(flags) && isCode(flags))
{
//Get the mnemonic at this address
res = ua_mnem(eaAddr, mnem, sizeof(mnem)-1);
// Check the mnemonic of this address against all
// mnemonics we're interested in.
for (int i = 0; instrs[i] != 0; i++)
{
if (cmd.itype == instrs[i])
{
bFound = 1;
}
}
//We have an instruction we're interested in
if(bFound)
{
//check the type of mnemonic.
/* msg("Instruction mnemonic at 0x%x :->\n", eaAddr);
msg(" Op0: n = %d type = %d reg = %d value = %a addr = %a\n",
cmd.Operands[0].n,
cmd.Operands[0].type,
cmd.Operands[0].reg,
cmd.Operands[0].value,
cmd.Operands[0].addr);
msg(" Op1: n = %d type = %d reg = %d value = %a addr = %a\n",
cmd.Operands[1].n,
cmd.Operands[1].type,
cmd.Operands[1].reg,
cmd.Operands[1].value,
cmd.Operands[1].addr);
*/
// Is the instruction Memory Reg [Base Reg + Index Reg + Displacement] phrase+addr?
// If so, then these need converting into offset addresses
if(cmd.Operands[0].type == o_displ)
{
//r0 is a special register and should not be offsetted
if(cmd.Operands[0].reg!= 0)
if(cmd.Operands[0].addr >= 0x00ff)
MakeC166Offset(eaAddr, 0);
}
else if(cmd.Operands[1].type == o_displ)
{
//r0 is a special register and should not be offsetted
if(cmd.Operands[1].reg!= 0)
if(cmd.Operands[1].addr >= 0x00ff)
MakeC166Offset(eaAddr, 1);
}
}
}
eaAddr++;
}
hide_wait_box();
return 1;
}
//Makes C166 offsets utilising the correct DPP value
// eaAddr = Address of the instruction
// nOp = Operand Number
void BoschHelper::MakeC166Offset(ea_t eaAddr, int nOp)
{
//Translate the address we get into a real address
int iReg;
ea_t eaDpp;
sel_t selSelector;
//Find out what DPP the address we've found lives in.
//The DPP selector is the top two bits
eaDpp = (cmd.Operands[1].addr & 0xc000) >> 14;
if(eaDpp == 0)
{
iReg = str2reg("DPP0");
}
else if (eaDpp==1)
{
iReg = str2reg("DPP1");
}
else if (eaDpp==2)
{
iReg = str2reg("DPP2");
}
else
{
iReg = str2reg("DPP3");
}
//Get the value of the selected register
//Don't ask me why but the register needs to be multiplied by 16 to become the base
selSelector = get_segreg(eaAddr, iReg) << 4;
ea_t eaOffsetBase = get_offbase(eaAddr, nOp);//For information, not used
msg("**** At address 0x%x DPP number 0x%x for Register 0x%x, is 0x%x. Op is 0x%x. Offset base is 0x%x\n", eaAddr, eaDpp, iReg, selSelector, nOp, eaOffsetBase);
//Create the offset
if(op_offset(eaAddr, nOp, REF_OFF16, BADADDR, selSelector) == 0)
{
msg("op_offset failed\n");
}
}
// Loops through the binary and tries to make code offsets from implicit references
// e.g. movb [r5+0E0A4h], rl4 = movb [r5+word_E0A4], rl4
//mov r4, #0F9F6h ; Move Word <- Here's the address
//mov r5, #0 ; Move Word <- Here's the segment
//movbz r2, rl6 ; Move Byte Zero Extend
//shl r2, #1 ; Shift Left
//mov r3, #0 ; Move Word
//add r4, r2 ; Integer Addition
//addc r5, r3 ; Integer Addition with Carry
//exts r5, #1 ; Begin Extended Segment Sequence <- This requires a segment
//mov r12, [r4] ; Move Word with phrase <- This requires an address
bool BoschHelper::FindAndCreateImplicitOffsets(ea_t eaStartAddr, ea_t eaEndAddr)
{
msg("Finding implicit offsets and trying to create them from 0x%x through to 0x%x\n", eaStartAddr, eaEndAddr);
ea_t eaAddr, eaLenOfGeneratedCode;
int iCount, iReturns;
//
// Look for known function that will contain offsets within the code
//
eaAddr = eaStartAddr;
eaLenOfGeneratedCode = 1;
iCount = iReturns = 1;
// Instructions we know that contain addresses.
int instrs[] = { C166_mov, 0 };
char mnem[MAXSTR];
const char *res;
bool bFound;
show_wait_box("Searching for implicit offsets...");
for (eaAddr; eaAddr<eaEndAddr;)
{
//Find instructions we know will have offsets in them
bFound = 0;
if ((eaAddr % 0x100) == 0)
{
showAddr(eaAddr);
if (wasBreak())
break;
}
//Get the flags for this address
flags_t flags = getFlags(eaAddr);
//Only look at the address if it's a head byte
//i.e. the start of an instruction and its code
if(isHead(flags) && isCode(flags))
{
//Get the mnemonic at this address
res = ua_mnem(eaAddr, mnem, sizeof(mnem)-1);
// Check the mnemonic of this address against all
// mnemonics we're interested in.
for (int i = 0; instrs[i] != 0; i++)
{
if (cmd.itype == instrs[i])
{
bFound = 1;
}
}
//We have an instruction we're interested in
if(bFound)
{
//check the type of mnemonic.
msg("Instruction mnemonic at 0x%x :->\n", eaAddr);
msg(" Op0: n = %d type = %d reg = %d value = %a addr = %a\n",
cmd.Operands[0].n,
cmd.Operands[0].type,
cmd.Operands[0].reg,
cmd.Operands[0].value,
cmd.Operands[0].addr);
msg(" Op1: n = %d type = %d reg = %d value = %a addr = %a\n",
cmd.Operands[1].n,
cmd.Operands[1].type,
cmd.Operands[1].reg,
cmd.Operands[1].value,
cmd.Operands[1].addr);
// Is the instruction a Memory Ref [Base Reg + Index Reg] and not r0?
// If so, then we need to back track and see when it's loaded with an immediate
// Need to do this for cmd.Operands[0] and cmd.Operands[1]
// Also backtrack one instruction and see if there's a "exts"
if((cmd.Operands[1].type == o_phrase) & (cmd.Operands[1].reg != 0))
{
msg("We're at a phrase and need to look for where r%a was immediate loaded.\n", cmd.Operands[1].reg);
// We need to backtrack & find where this register was loaded immediate at op1
//r0 is a special register and should not be offsetted
// if(cmd.Operands[1].reg!= 0)
// if(cmd.Operands[1].addr >= 0x00ff)
// MakeC166Offset(eaAddr, 1);
}
}
}
eaAddr++;
}
hide_wait_box();
return 1;
}
//////////////////////////////////////////////////////////////////////
// Implementation
//////////////////////////////////////////////////////////////////////
//Automatically disassembles the code and tries to make subroutines
void BoschHelper::MakeDissCode(string sECU)
{
if(sECU == "bNewME711")
{
CreateDissCode(0x00000, 0xdfff);
CreateDissCode(0x10000, 0xcffff);
//CreateDissCode(0x800014, 0x803422);
CreateDissCode(0x800014, 0x8fffff);
//CreateDissCode(0x800014, 0x80ffff);
//RAM is @ 0x380000 - 0x383fff - size 0x4000
//Data is @0x8
CreateDissCode(0x81e28c, 0x81ea40);
}
else if (sECU == "ME761Astra")
{
CreateDissCode(0x0000, 0x3fff);
CreateDissCode(0x4000, 0x7fff);
CreateDissCode(0x10000, 0xaffff);
CreateDissCode(0xc0000, 0xcff00);
}
else
{
CreateDissCode(0x00000, 0x1ff);
CreateDissCode(0x700, 0x7fff);
CreateDissCode(0x800000, 0x810000);
CreateDissCode(0x830000, 0x8fff00);
}
}
//No longer used
//void BoschHelper::MakeSubroutines(void)
//{
// ea_t eaResult=0, eaLast=0;
//
// add_func(eaResult, BADADDR);
//
// while(eaResult != BADADDR)
// {
// eaResult = find_unknown(eaLast, SEARCH_DOWN);
// if(add_func(eaResult, BADADDR))
// msg("Function created at %x\n", eaResult);
//
// if( (eaResult > MAP_AREA_START) & (eaResult < MAP_AREA_FINISH) )
// {
// msg("Ignoring data - within MAP area\n");
// eaResult = MAP_AREA_FINISH;
// }
// if(eaResult == BADADDR)
// msg("End of Auto-Disassemble analysis loop\n");
//
// eaLast = eaResult;
// }
//
//}
//Makes the segments of the disassembly
//void BoschHelper::MakeSegments(BOOL bNewME711)
void BoschHelper::MakeSegments(string sECU)
{
//bool BoschHelper::CreateC16xBoschSegments(ea_t eaParagraph, unsigned int iNumSegsToCreate, const char *sclass, sel_t dpp0, sel_t dpp1, sel_t dpp2, sel_t dpp3)
if(sECU == "bNewME711")
{
//CreateC16xBoschSegments(0x0000, 4, "ABS", 0x0, 0x1, 2, 3);
CreateC16xSmallBoschSegments(0x0000, 0x8000, "MEM_EXT", "CODE", 0x23f, 0x3c, 0x0e0, 3);
//SFR
CreateC16xSmallBoschSegments(0x8000, 0xE000, "MEM_EXT", "CODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xSmallBoschSegments(0xE000, 0xE800, "XRAM", "DATA", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xSmallBoschSegments(0xE800, 0xEf00, "RESERVED", "BSS", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xSmallBoschSegments(0xEf00, 0xf000, "CAN1", "DATA", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xSmallBoschSegments(0xf000, 0xf200, "E_SFR", "DATA", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xSmallBoschSegments(0xf200, 0xf600, "RESERVED", "BSS", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xSmallBoschSegments(0xf600, 0xfE00, "IRAM", "CODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xSmallBoschSegments(0xfe00, 0x10000, "SFR", "DATA", 0x23f, 0x3c, 0x0e0, 3);
//MPU ROM
CreateC16xBoschSegments(0x1000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0x2000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0x3000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0x4000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0x5000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0x6000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0x7000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0x8000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0x9000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0xa000, 4, "MPUCODE", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0xb000, 4, "DATA", 0x23f, 0x3c, 0x0e0, 3);
CreateC16xBoschSegments(0xc000, 4, "DATA", 0x23f, 0x3c, 0x0e0, 3);
//RAM
CreateC16xBoschSegments(0xe000, 4, "CODERAM", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0xf000, 4, "CODERAM", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x38000, 4, "DATARAM", 0x23f, 0x3c, 0xe0, 3);
//ROM
CreateC16xBoschSegments(0x80000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x81000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x82000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x83000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x84000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x85000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x86000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x87000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x88000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x89000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x8a000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x8b000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x8c000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x8d000, 4, "CODE", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x8e000, 4, "DATA", 0x23f, 0x3c, 0xe0, 3);
CreateC16xBoschSegments(0x8f000, 4, "DATA", 0x23f, 0x3c, 0xe0, 3);
}
else if (sECU == "ME761Astra")
{
CreateC16xSmallBoschSegments(0x0000, 0x8000, "MEM_EXT", "CODE", 0x0, 0x1, 0x2, 0x3);
//SFR
CreateC16xSmallBoschSegments(0x8000, 0xE000, "MEM_EXT", "CODE", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xE000, 0xE800, "XRAM", "DATA", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xE800, 0xEf00, "RESERVED", "BSS", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xEf00, 0xf000, "CAN1", "DATA", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xf000, 0xf200, "E_SFR", "DATA", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xf200, 0xf600, "RESERVED", "BSS", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xf600, 0xfE00, "IRAM", "CODE", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xfe00, 0x10000, "SFR", "DATA", 0x0, 0x1, 0x2, 0x3);
//RAM
CreateC16xBoschSegments(0xf000, 4, "DATA" , 0x2c, 0x2d, 0x3c, 3);
//ROM
CreateC16xBoschSegments(0x1000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0x2000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0x3000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0x4000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0x5000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0x6000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0x7000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0x8000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0x9000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0xa000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0xb000, 4, "DATA", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0xc000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
CreateC16xBoschSegments(0xd000, 4, "CODE", 0x2c, 0x2d, 0x3c, 3);
}
else
{
CreateC16xSmallBoschSegments(0x0000, 0x8000, "MEM_EXT", "CODE", 0x0, 0x1, 0x2, 0x3);
//SFR
CreateC16xSmallBoschSegments(0x8000, 0xE000, "MEM_EXT", "CODE", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xE000, 0xE800, "XRAM", "DATA", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xE800, 0xEf00, "RESERVED", "BSS", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xEf00, 0xf000, "CAN1", "DATA", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xf000, 0xf200, "E_SFR", "DATA", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xf200, 0xf600, "RESERVED", "BSS", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xf600, 0xfE00, "IRAM", "CODE", 0x0, 0x1, 0x2, 0x3);
CreateC16xSmallBoschSegments(0xfe00, 0x10000, "SFR", "DATA", 0x0, 0x1, 0x2, 0x3);
//RAM
CreateC16xBoschSegments(0x38000, 2, "DATA" , 0x204, 0x205, 0xe0, 3);
//ROM
CreateC16xBoschSegments(0x80000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x81000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x82000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x83000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x84000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x85000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x86000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x87000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x88000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x89000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x8a000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x8b000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x8c000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x8d000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x8e000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
CreateC16xBoschSegments(0x8f000, 4, "CODE", 0x204, 0x205, 0xe0, 3);
}
}
//Looks for signatures of commonly known functions and set their name.
//Test routine!
//void BoschHelper::SearchForFuncSigs(BOOL bNewME711)
//{
// //No longer used
// const uchar test[]={0xfa, 0x82, 0xd8, 0x00, 0xfa, 0xff, 0xDC, 0x00};
// ea_t eaFound;
//
// eaFound = FindBinaryWithDontCare((uchar*)test, 8, 0x800000, 0x80ffff);
// if(eaFound != BADADDR)
// msg("Found Sig at 0x%x\n", eaFound);
// else
// msg("Sig not found\n");
//}
//Looks for Bosch DTC setting fields.
void BoschHelper::SearchForDTCFlagSetting(string sECU)
{
//Create the enum constants first
enum_t enumtID;
//The DTC enum for low bits
enumtID = add_enum(BADADDR, "DTCLBit", 0x1100000);//Create the enum
set_enum_bf(enumtID, 1);//Set the enum to a bitfield
//Now fill the enum structure
add_enum_member(enumtID,"DTCBit_L0", 0x1, 0x1);
add_enum_member(enumtID,"DTCBit_L1", 0x2, 0x2);
add_enum_member(enumtID,"DTCBit_L2", 0x4, 0x4);
add_enum_member(enumtID,"DTCBit_L3", 0x8, 0x8);
add_enum_member(enumtID,"DTCBit_L4", 0x10, 0x10);
add_enum_member(enumtID,"DTCBit_L5", 0x20, 0x20);
add_enum_member(enumtID,"DTCBit_L6", 0x40, 0x40);
add_enum_member(enumtID,"DTCBit_L7", 0x80, 0x80);
//The DTC enum for high bits
enumtID = add_enum(BADADDR, "DTCHBit", 0x1100000);//Create the enum
set_enum_bf(enumtID, 1);//Set the enum to a bitfield
//Now fill the enum structure
add_enum_member(enumtID,"DTCFieldA_H0", 0x1, 0x1);
set_enum_cmt(get_const(enumtID, 0x1, NULL, 0x1),"Select DTC Group A",1);
//set_enum_cmt(get_const(enumtID, 0x1, NULL, 0x1), "Select DTC Group A", 1);
add_enum_member(enumtID, "DTCFieldB_H1", 0x2, 0x2);
set_enum_cmt(get_const(enumtID, 0x2, NULL, 0x2),"Select DTC Group B",1);
add_enum_member(enumtID,"DTCFieldC_H2", 0x4, 0x4);
set_enum_cmt(get_const(enumtID, 0x4, NULL, 0x4),"Select DTC Group C",1);
add_enum_member(enumtID,"DTCFieldD_H3", 0x8, 0x8);
set_enum_cmt(get_const(enumtID, 0x8, NULL, 0x8),"Select DTC Group D",1);
add_enum_member(enumtID,"DTCBit_H4", 0x10, 0x10);
add_enum_member(enumtID,"DTCBit_H5", 0x20, 0x20);
add_enum_member(enumtID,"DTCBit_H6", 0x40, 0x40);
add_enum_member(enumtID,"DTCBit_H7", 0x80, 0x80);
//Search the disassembly for enum flag setting
if(sECU == "bNewME711")
{
EnumDTCflags(0x00000, 0xffffff);
}
else if (sECU == "ME761Astra")
{
EnumDTCflags(0x10000, 0xff000);
}
else
{
EnumDTCflags(0x820000, 0x8ff000);
}
}
//Looks for specific binary patterns and then makes a subroutine and comments it
void BoschHelper::SearchForFuncSigsAndThenCmt(string sECU)
{
if (sECU == "ME761Astra")
{
msg("*** ME761Astra 1st pass\n");
functionsigsclass.FindFuncSigsAndComment(0x0, 0x3fff);
msg("*** ME761Astra 2nd pass\n");
functionsigsclass.FindFuncSigsAndComment(0x4000, 0x7fff);
msg("*** ME761Astra 3rd pass\n");
functionsigsclass.FindFuncSigsAndComment(0x8000, 0xdfff);
msg("*** ME761Astra 4th pass\n");
functionsigsclass.FindFuncSigsAndComment(0x10000, 0xdffff);
}
else
{
msg("Everything Else\n");
functionsigsclass.FindFuncSigsAndComment(0x0, 0xffffff);
}
// FindFuncSigsAndComment(0x8de4b4, 0x8de566);
}
//Looks for instructions that will probably contain an offset. When found it creates them.
void BoschHelper::SearchForArrayOffsetsAndThenCreate(string sECU)
{
if(sECU == "bNewME711")
{
FindAndCreateArrayOffsets(0x0, 0xffffff);
}
else if (sECU == "ME761Astra")
{
FindAndCreateArrayOffsets(0x0, 0x3fff);
FindAndCreateArrayOffsets(0x4000, 0x7fff);
FindAndCreateArrayOffsets(0x8000, 0xdfff);
FindAndCreateArrayOffsets(0x10000, 0xdffff);
}
else
{
FindAndCreateArrayOffsets(0x0, 0x8fffff);
}
// FindAndCreateImplicitOffsets(0x8694b4, 0x8694ce);
}

52
BoschHelper.h Normal file
View File

@ -0,0 +1,52 @@
// BoschHelper.h: interface for the BoschHelper class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BOSCHHELPER_H__9F97668B_19D4_4904_923E_1C391DF3A947__INCLUDED_)
#define AFX_BOSCHHELPER_H__9F97668B_19D4_4904_923E_1C391DF3A947__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "FunctionSigs.h"
#include <string>
using namespace std;
#define ROM_START 0x800000
#define MAP_AREA_START 0x810000
#define MAP_AREA_FINISH 0x822000
class BoschHelper : public FunctionSigs
{
public:
BoschHelper();
virtual ~BoschHelper();
FunctionSigs functionsigsclass;
sel_t mSelector;// Used to count the selector
//helper functions
protected:
bool CreateDissCode(ea_t eaStartAddr, ea_t eaEndAddr);// Loops through the binary and makes disassembled code
bool BoschHelper::EnumDTCflags(ea_t eaStartAddr, ea_t eaEndAddr);// Loops through the binary and searches for where DTC flags are being set.
bool SetC16xRegs(const char *RegName, sel_t value);// Sets the default register values on the C16x CPU
bool CreateC16xSmallBoschSegments(ea_t eaStartAddr, ea_t eaEndAddr, char* cName, const char *sclass, sel_t dpp0, sel_t dpp1, sel_t dpp2, sel_t dpp3);// Creates a Bosch segment and default registers
bool CreateC16xBoschSegments(ea_t eaParagraph, unsigned int iNumSegsToCreate, const char *sclass, sel_t dpp0, sel_t dpp1, sel_t dpp2, sel_t dpp3);// Creates the correct Bosch segments and default registers
bool FindAndCreateArrayOffsets(ea_t eaStartAddr, ea_t eaEndAddr);// Loops through the binary and tries to make code offsets
void MakeC166Offset(ea_t eaAddr, int nOp);//Makes C166 offsets utilising the correct DPP value
bool FindAndCreateImplicitOffsets(ea_t eaStartAddr, ea_t eaEndAddr);
//implementation
public:
void MakeDissCode(string sECU);//Automatically disassembles the code and tries to make subroutines
//void MakeSubroutines(void);//No longer used
void MakeSegments(string sECU);//Makes the segments of the disassembly
//void SearchForFuncSigs(BOOL bNewME711);//Looks for signatures of commonly known functions and set their name.
void SearchForDTCFlagSetting(string sECU);//Looks for Bosch DTC setting fields.
void SearchForFuncSigsAndThenCmt(string sECU);//Looks for specific binary patterns and then makes a subroutine and comments it
void SearchForArrayOffsetsAndThenCreate(string sECU);//Looks for instructions that will probably contain an offset. When found it creates them.
};
#endif // !defined(AFX_BOSCHHELPER_H__9F97668B_19D4_4904_923E_1C391DF3A947__INCLUDED_)

View File

@ -0,0 +1,26 @@
I'm been pulling my hair out with trying to figure out how to create an offset with the IDA SDK.
Here's a snippet of code:
Seg0x200@800000:2818 loc_802818: ; CODE XREF: sub_80274E+E0.j
Seg0x200@800000:2818 movbz r12, rl6
Seg0x200@800000:281A shl r12, #1
Seg0x200@800000:281C extp #0, #1
Seg0x200@800000:2820 mov r4, [r12+430h]
Seg0x200@800000:2824 mov [r12+0E210h], r4
If I select the offset and press "O", IDA correctly creates the offset.
Seg0x200@800000:2818 loc_802818: ; CODE XREF: sub_80274E+E0.j
Seg0x200@800000:2818 movbz r12, rl6
Seg0x200@800000:281A shl r12, #1
Seg0x200@800000:281C extp #0, #1
Seg0x200@800000:2820 mov r4, [r12+word_430]
Seg0x200@800000:2824 mov [r12+word_E210], r4
If I execute an IDC script with this code:
OpOff(0x802820, 1, 0x800000);
OpOff(0x802824, 0, 0x800000);
This works great... however, I cannot get the same working in the sdk :confused:

1271
FunctionSigs.cpp Normal file

File diff suppressed because it is too large Load Diff

28
FunctionSigs.h Normal file
View File

@ -0,0 +1,28 @@
// FunctionSigs.h: interface for the FunctionSigs class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_FUNCTIONSIGS_H__C6DB9FEB_257B_46A5_A944_3629C2B0D33C__INCLUDED_)
#define AFX_FUNCTIONSIGS_H__C6DB9FEB_257B_46A5_A944_3629C2B0D33C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class FunctionSigs
{
public:
FunctionSigs();
virtual ~FunctionSigs();
private:
public:
ea_t FindBinaryWithDontCare(uchar* ubinstr, unsigned __int32 nSLength, ea_t eaStartAddress, ea_t eaEndAddr);//Finds the given binary string in the given binary. If 0xff then this is don't care
ea_t CreateFunctionAndComment(ea_t eaAddr, unsigned char* pFuncName, unsigned char* pComment, unsigned int iTries);// Creates a function at the address and auto comments it
void Comment(ea_t eaAddr, unsigned char* pDataName, unsigned char* pComment, unsigned int iTries);//Comments the address given
public:
void FindFuncSigsAndComment(ea_t eaStartAddr, ea_t eaEndAddr);//Looks for specific binary patterns and then makes a subroutine and comments it
};
#endif // !defined(AFX_FUNCTIONSIGS_H__C6DB9FEB_257B_46A5_A944_3629C2B0D33C__INCLUDED_)

95
IDAMemCopyPaste.cpp Normal file
View File

@ -0,0 +1,95 @@
// IDAMemCopyPaste.cpp: implementation of the IDAMemCopyPaste class.
//
//////////////////////////////////////////////////////////////////////
//Standard Defs
typedef int BOOL;
#define FALSE 0
#define TRUE 1
#define NULL 0
#include <pro.h>
#include <kernwin.hpp>
#include <bytes.hpp>
//#include <funcs.hpp>
//#include <lines.hpp>
//#include <name.hpp>
//#include <ida.hpp>
//#include <idp.hpp>
//#include <loader.hpp>
#include "IDAMemCopyPaste.h"//
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//,Construction/Destruction
//////////////////////////////////////////////////////////////////////
IDAMemCopyPaste::IDAMemCopyPaste()
{
}
IDAMemCopyPaste::~IDAMemCopyPaste()
{
}
//////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////
#define MAX_COPYPASTE 1024
// This will hold our copied buffer for pasting
char data[MAX_COPYPASTE];
void IDAMemCopyPaste::copy_buffer(ea_t eaStartAddr, ea_t eaEndAddr)
{
ssize_t size;
// Work out the size, make sure it doesn't exceed the buffer
// we have allocated.
size = eaEndAddr - eaStartAddr;
if (size > MAX_COPYPASTE)
{
warning("You can only copy a max of %d bytes\n", MAX_COPYPASTE);
return;
}
// Get the bytes from the file, store it in our buffer
if (get_many_bytes(eaStartAddr, data, size))
{
msg("Successfully copied %d bytes from %a into memory.\n", size, eaStartAddr);
}
else
{
msg("FAILED to copy %d bytes from %a into memory.\n", size, eaStartAddr);
}
}
void IDAMemCopyPaste::paste_buffer(ea_t eaStartAddr, ea_t eaEndAddr)
{
ssize_t size;
// Work out the size, make sure it doesn't exceed the buffer
// we have allocated.
size = eaEndAddr - eaStartAddr;
if (size > MAX_COPYPASTE)
{
warning("You can only copy a max of %d bytes\n", MAX_COPYPASTE);
return;
}
// Patch the binary (paste)
patch_many_bytes(eaStartAddr, data, size);
msg("Patched %d bytes at %a.\n", size, eaStartAddr);
}
//////////////////////////////////////////////////////////////////////
// Implementation
//////////////////////////////////////////////////////////////////////
//Looks for specific binary patterns and then makes a subroutine and comments it
void IDAMemCopyPaste::FindFuncSigsAndComment(void)
{
}

29
IDAMemCopyPaste.h Normal file
View File

@ -0,0 +1,29 @@
// IDAMemCopyPaste.h: interface for the IDAMemCopyPaste class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_IDAMemCopyPaste_H__C6DB9FEB_257B_46A5_A944_3629C2B0D33C__INCLUDED_)
#define AFX_IDAMemCopyPaste_H__C6DB9FEB_257B_46A5_A944_3629C2B0D33C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class IDAMemCopyPaste
{
public:
IDAMemCopyPaste();
virtual ~IDAMemCopyPaste();
private:
void copy_buffer(ea_t eaStartAddr, ea_t eaEndAddr);
void paste_buffer(ea_t eaStartAddr, ea_t eaEndAddr);
public:
public:
void FindFuncSigsAndComment(void);//Looks for specific binary patterns and then makes a subroutine and comments it
};
#endif // !defined(AFX_IDAMemCopyPaste_H__C6DB9FEB_257B_46A5_A944_3629C2B0D33C__INCLUDED_)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

118
Programming Via OBD-II.txt Normal file
View File

@ -0,0 +1,118 @@
From http://www.streetcarforums.com/showthread.php?t=52923&page=10
Let's assume you have a KWP2000 connection with your VAG group ECU
Then let's go send these messages:
82 : 2 data bytes
01
F1
1A : ISO 14230-3 ReadECUIdentification
92 : systemSupplierSpecific
20 : CRC
The ECU should respond with
87 : 7 data bytes
F1
01
5A : ISO 14230-3 positive reply
92 : systemSupplierSpecific
VV
WW
XX
YY
ZZ
CS : CRC
Now compute the following
ecuid = (VV+WW+XX+YY+ZZ) & 0x3f
Then send:
82 : 2 data bytes
01
F1
27 : ISO 14230-3 SecurityAccessRequest
01 : Request Seed
9C : CRC
The ECU should respond with
86 :6 data bytes
01
F1
67 : ISO 14230-3 positive reply
01 : Request Seed
WW : Seed MSB
XX
YY
ZZ : Seed LSB
CS : CRC
Now compute the following
Seed = (WW<<24)+(XX<<16)+(YY<<8)+(ZZ)
unsigned int table[64] =
{
0x0A221289,0x144890A1,0x24212491,0x290A0285,
0x42145091,0x504822C1,0x0A24C4C1,0x14252229,
0x24250525,0x2510A491,0x28488863,0x29148885,
0x422184A5,0x49128521,0x50844A85,0x620CC211,
0x124452A9,0x18932251,0x2424A459,0x29149521,
0x42352621,0x4A512289,0x52A48911,0x11891475,
0x22346523,0x4A3118D1,0x64497111,0x0AE34529,
0x15398989,0x22324A67,0x2D12B489,0x132A4A75,
0x19B13469,0x25D2C453,0x4949349B,0x524E9259,
0x1964CA6B,0x24F5249B,0x28979175,0x352A5959,
0x3A391749,0x51D44EA9,0x564A4F25,0x6AD52649,
0x76493925,0x25DE52C9,0x332E9333,0x68D64997,
0x494947FB,0x33749ACF,0x5AD55B5D,0x7F272A4F,
0x35BD5B75,0x3F5AD55D,0x5B5B6DAD,0x6B5DAD6B,
0x75B57AD5,0x5DBAD56F,0x6DBF6AAD,0x75775EB5,
0x5AEDFED5,0x6B5F7DD5,0x6F757B6B,0x5FBD5DBD
};
for (int i=0; i<5; i++)
{
if ((seed & 0x80000000) == 0)
{
seed = (table[ecuid]) ^ (seed << 1);
}
else
{
seed = (seed << 1);
}
}
Then send:
88 : 8 data bytes
01
F1
27 : ISO 14230-3 SecurityAccessRequest
02 : Send Key
WW : (seed >> 24 ) & 0xff
XX : (seed >> 16 ) & 0xff
YY : (seed >> 8 ) & 0xff
ZZ : (seed ) & 0xff
00
00
CS : CRC
The ECU should respond with
83 : 3 data bytes
01
F1
67 : ISO 14230-3 positive reply
02 : Send Key
34 : Not sure what this means
12 : CRC
Secure access granted, now you can read/write anything (eeprom etc.)
Enjoy!

71
SafFunctionSigs.h Normal file
View File

@ -0,0 +1,71 @@
// FunctionSigs.h: function signatures for the BoschHelper class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BOSCHFUNCTIONSIGS_H__56f34b1a_19D4_4904_923E_1C391DF3A947__INCLUDED_)
#define AFX_BOSCHFUNCTIONSIGS_H__56f34b1a_19D4_4904_923E_1C391DF3A947__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//FunctionSigs
//3d array declaration
#define NUM_SIGS 0x04
unsigned char fs_functionnames[NUM_SIGS][255] = {
{ "CRC8Sub" },
{"RSACallingSub"},
{"CRC32ME71Sub"},
{"CRC32ME75Sub"}
};
unsigned char fs_functioncomments[NUM_SIGS][255] = {
{"Works out a basic CRC8 checksum"},
{"Deals with the RSA checking"},
{"Works out the CRC32 checksums"},
{"Works out the CRC32 checksums"}
};
unsigned char fs_sigs[NUM_SIGS][118] = {
//CRC8
{0x88,0x90,0x88,0x80,0x88,0x70,0x88,0x60,0x28,0x04,0xc2,0xf4,0xff,0xff,0xc2,0xf5,
0xff,0xff,0x1b,0x45,0xf2,0xf4,0x0e,0xfe,0xc2,0xf2,0xff,0xff,0x1b,0x42,0xf2,0xf5,
0x0c,0xfe,0xf2,0xf4,0x0e,0xfe,0x26,0xf4,0x98,0xf3,0x36,0xf5,0x28,0x00,0x3d,0x04,
0x8a,0xff,0x02,0xff,0xea,0x00,0xff,0xff,0xf2,0xf4,0xff,0xff,0x66,0xf4,0x00,0x80,
0x2d,0x1d,0x84,0x00,0xff,0xff,0xa8,0x40,0x66,0xf4,0x00,0x0f,0x46,0xf4,0x00,0x01,
0x2d,0x15,0xa8,0x40,0x0a,0xf4,0x02,0x02,0xb8,0x40,0xa8,0x50,0x1a,0xf5,0x20,0x20,
0xb8,0x50,0xa8,0x40,0x0a,0xf4,0x01,0x01,0xb8,0x40,0xa8,0x50,0x1a,0xf5,0x01,0x0f,
0xb8,0x50,0x88,0x50,0xe0,0x1c},
//RSA Calling Sub
{0x8a,0xff,0x52,0xff,0xda,0xff,0xff,0xff,0xf3,0xf8,0xff,0xff,0x2d,0x27,0x25,0x8f,
0xff,0xff,0xf3,0xfa,0xff,0xff,0x49,0xa5,0xfd,0x19,0xff,0xff,0xff,0xff,0xe6,0xfc,
0xff,0xff,0xe0,0x0d,0xe6,0xfe,0x10,0x00,0xda,0xff,0xff,0xff,0xe6,0xfc,0xff,0xff,
0xe0,0x0d,0xe6,0xfe},
//CRC32 ME71 Sub
{0x88,0x90,0x88,0x80,0x88,0x70,0x88,0x60,0x28,0x06,0xc2,0xf4,0xff,0xff,0xc2,0xf5,
0xff,0xff,0x1b,0x45,0xf2,0xf4,0x0e,0xfe,0xc2,0xf2,0xff,0xff,0x1b,0x42,0xf2,0xf5,
0x0c,0xfe,0xf2,0xf4,0x0e,0xfe,0x26,0xf4,0x98,0xf3,0x36,0xf5,0x28,0x00,0xea,0x20,
0xff,0xff,0xf3,0xf8,0xff,0xbd,0x47,0xf8,0x33,0x00,0xea,0x30,0xff,0xff,0xf3,0xfa,
0xff,0xbd,0x47,0xfa,0x33,0x00,0xea,0x30,0xff,0xff,0xff,0xff,0xf3,0xf6,0xff,0xff,
0xea,0x30,0xff,0xff,0xf3,0xf4,0xff,0xff,0x47,0xf4,0x33,0x00,0xea,0x30,0xff,0xff,
0xe1,0x12,0xf7,0xf2,0xff,0xff,0xe1,0x28,0xf7,0xf8,0xff,0xff,0xf3,0xf8,0xff,0xbd,
0xf7,0xf8,0xff,0xff,0xf7,0xfa},
//CRC32 ME75 Sub
{0x88,0x90,0x88,0x80,0x88,0x70,0x88,0x60,0x28,0x06,0xc2,0xf4,0xff,0xa8,0xc2,0xf5,
0xff,0xa8,0x1b,0x45,0xf2,0xf4,0x0e,0xfe,0xc2,0xf2,0xff,0xa8,0x1b,0x42,0xf2,0xf5,
0x0c,0xfe,0xf2,0xf4,0x0e,0xfe,0x26,0xf4,0x98,0xf3,0x36,0xf5,0x28,0x00,0xea,0x20,
0xff,0xff,0xf3,0xf8,0x7a,0xbb,0x47,0xf8,0x33,0x00,0xea,0x30,0xff,0xff,0xf3,0xfa,
0x8a,0xbb,0x47,0xfa,0x33,0x00,0xea,0x30,0xff,0xff,0x4f,0xff,0xf3,0xf6,0xff,0xa8,
0xea,0x30,0xff,0xff,0xf3,0xf4,0xff,0xa8,0x47,0xf4,0x33,0x00,0xea,0x30,0xff,0xff,
0xe1,0x12,0xf7,0xf2,0xff,0xa8,0xe1,0x28,0xf7,0xf8,0xff,0xa8,0xf3,0xf8,0x7a,0xbb,
0xf7,0xf8,0xff,0xa8,0xf7,0xfa},
};
unsigned char fs_siglen[NUM_SIGS] = { 118, 52, 118, 118 };
#endif // !defined(AFX_BOSCHFUNCTIONSIGS_H__56f34b1a_19D4_4904_923E_1C391DF3A947__INCLUDED_)

175
TableSigs.cpp Normal file
View File

@ -0,0 +1,175 @@
// TableSigs.cpp: implementation of the TableSigs class.
//
//////////////////////////////////////////////////////////////////////
//Standard Defs
typedef int BOOL;
#define FALSE 0
#define TRUE 1
#define NULL 0
#include <pro.h>
#include <kernwin.hpp>
#include <bytes.hpp>
//#include <funcs.hpp>
#include <lines.hpp>
#include <name.hpp>
#include "TableSigs.h" //Has all the Table signatures stored within it
//////////////////////////////////////////////////////////////////////
// Table Signatures
//////////////////////////////////////////////////////////////////////
#define NUM_DATA_SIGS 3
unsigned char ts_Tablenames[NUM_DATA_SIGS][255] =
{
{"LineariseMAF"},
{"LineariseEGT"},
{"LineariseCTS"}
};
unsigned char ts_Tablecomments[NUM_DATA_SIGS][255] =
{
{"Table to linearise the Hot Wire MAF output"},
{"Table to linearise the EGT output"},
{"Table to linearise the CTS output"}
};
unsigned char ts_sigs[NUM_DATA_SIGS][310] =
{
//Linearise MAF
{0x93,0x05,0x9B,0x05,0xA2,0x05,0xAA,0x05,0xB2,0x05,0xB9,0x05,0xC1,0x05,0xC8,0x05},
//Linearise EGT
{0x12,0x00,0x00,0x00,0x9A,0x19,0x17,0x28,0x39,0x36,0x0B,0x44,0x9D,0x51,0xFA,0x5E},
//Linearise CTS
{0x14,0x00,0x00,0x00,0x24,0x00,0x2C,0x00,0x38,0x00,0x44,0x00,0x58,0x00,0x70,0x00}
};
unsigned int ts_siglen[NUM_DATA_SIGS] = {16, 16, 16};
//////////////////////////////////////////////////////////////////////
//,Construction/Destruction
//////////////////////////////////////////////////////////////////////
TableSigs::TableSigs()
{
}
TableSigs::~TableSigs()
{
}
//////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////
//Finds the given binary string in the given binary. If 0xff then this is don't care
ea_t TableSigs::FindBinaryWithDontCare(uchar* ubinstr,unsigned __int32 nSLength,ea_t eaStartAddress,ea_t eaEndAddr)
{
ea_t eaAddr = BADADDR,eaSearchAddr=0,nIndexA=0,nIndexB=0;
uchar nRead=0;
int iBit = 0;
ulong v=0;
// ea1stAddr = find_binary(ea_t startea,ea_t endea,ubinstr,16,sflag);
// msg("FindBinaryWithDontCare()");
for(nIndexA=eaStartAddress; nIndexA < eaEndAddr;)
{
eaAddr = nIndexA;//Store where we are.
nRead = get_8bit(nIndexA,v,iBit);//Read 8bits but remember that nIndexA is automatically incremented
if (nIndexA==BADADDR)//Have we ran out of bytes?
{
return BADADDR;
}
if (nIndexA>= (eaEndAddr-1))
return BADADDR;
if(nRead == *ubinstr)
{// We're matched for the 1st char,now check the rest
// msg("FindBinaryWithDontCare() found 0x%x at 0x%x with length %lu\n",nRead, nIndexA, nSLength);
for(nIndexB=1; nIndexB < nSLength; nIndexB++)
{
eaSearchAddr= eaAddr + nIndexB;
if(*(ubinstr+nIndexB) != 0xff) //check for don't care flag
{
nRead = get_8bit(eaSearchAddr,v,iBit);
// msg(": found 0x%x\n",nRead);
if (eaSearchAddr==BADADDR)//Have we ran out of bytes?
{
eaAddr=BADADDR;
// msg(" not found, ran beyond binary address space\n");
return BADADDR;
}
if(nRead != *(ubinstr+nIndexB))
{
// msg(" no match.\n");
eaAddr=BADADDR;
break;// No longer matched,exit this for(..) loop
}
else if(nIndexB==(nSLength-1))
{
// msg(" binary string matched at 0x%x.\n",eaAddr);
return eaAddr; // String completely matched
}
}
// else
// msg(": ignoring 0xff\n");
}
}
}
// msg("\n");
return eaAddr;
}
//////////////////////////////////////////////////////////////////////
// Implementation
//////////////////////////////////////////////////////////////////////
//Looks for specific binary patterns and then makes a table and comments it
void TableSigs::FindTablesAndComment(ea_t eaStartAddr, ea_t eaEndAddr)
{
msg("Finding Table signatures....\n");
unsigned int uIndex=0, iTry=0, iTries=0;
ea_t eaAddr;
char ucBuf[255];
for(uIndex=0; uIndex < NUM_DATA_SIGS; uIndex++)
{
msg("\nSearching for %s, len = %lu\n",ts_Tablenames[uIndex], ts_siglen[uIndex]);
for(iTry=eaStartAddr, iTries=0; iTry<eaEndAddr; iTry=eaAddr,iTries++)//We may have duplicates
{
//Search from the last place until the end of the database
eaAddr = FindBinaryWithDontCare(ts_sigs[uIndex], ts_siglen[uIndex], iTry, eaEndAddr);
if (eaAddr != BADADDR)
{
qsnprintf(ucBuf, 40, "%s_%x", (char*)ts_Tablenames[uIndex], eaAddr);//Create a unique name
set_name(eaAddr, ucBuf, SN_PUBLIC);//set the name of the Table
//We now want to comment the Table
// func_t* functTable = get_func(eaAddr); // get a pointer to the Table chunk
// del_func_cmt(functTable,1);//delete the existing comment
// update_func(functTable);
// set_func_cmt(functTable,(char*)ts_Tablecomments[uIndex],1);//Make a repeatable comment
// update_func(functTable);
// msg("Table finishes at: 0x0%x\n", functTable->endEA);
//Try the next set of addresses
// eaAddr=functTable->endEA;// the end of the Table just created.
}
else if(iTries==0)
{
msg(" Try %d, nothing found\n", iTries);
eaAddr+=0x1;//TO DO: Find the length of the Table just created.
break;
}
else
{
msg(" Try %d, no further Tables found\n", iTries);
eaAddr+=0x1;//TO DO: Find the length of the Table just created.
break;
}
// eaAddr+=0x10;//TO DO: Find the length of the Table just created.
// eaAddr=functTable->endEA;
}
}
}

28
TableSigs.h Normal file
View File

@ -0,0 +1,28 @@
// TableSigs.h: interface for the TableSigs class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TableSIGS_H__C6DB9FEB_257B_46A5_A944_3629C2BFD33C__INCLUDED_)
#define AFX_TableSIGS_H__C6DB9FEB_257B_46A5_A944_3629C2BFD33C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class TableSigs
{
public:
TableSigs();
virtual ~TableSigs();
private:
public:
ea_t FindBinaryWithDontCare(uchar* ubinstr, unsigned __int32 nSLength, ea_t eaStartAddress, ea_t eaEndAddr);//Finds the given binary string in the given binary. If 0xff then this is don't care
public:
void FindTablesAndComment(ea_t eaStartAddr, ea_t eaEndAddr);//Looks for specific binary patterns and then makes a subroutine and comments it
};
#endif // !defined(AFX_TableSIGS_H__C6DB9FEB_257B_46A5_A944_3629C2BFD33C__INCLUDED_)

View File

@ -0,0 +1,292 @@
/*
* This is a sample plugin module
*
* It can be compiled by any of the supported compilers:
*
* - Borland C++, CBuilder, free C++
* - Watcom C++ for DOS32
* - Watcom C++ for OS/2
* - Visual C++
*
*/
//Standard Defs
typedef int BOOL;
#define FALSE 0
#define TRUE 1
#define NULL 0
#include <ida.hpp>
#include <idp.hpp>
#include <expr.hpp>
#include <loader.hpp>
//#include <bytes.hpp>
//#include <kernwin.hpp>
//#include <name.hpp>
//#include <offset.hpp>
//#include <search.hpp>
#include "BoschHelper.h"
extern plugin_t PLUGIN;
BoschHelper boschcode; //our class
//--------------------------------------------------------------------------
// Example of a user-defined IDC function in C++
static const char myBoschME7xfunc5_args[] = { VT_LONG, VT_STR, 0 };
static error_t idaapi myfunc5(value_t *argv, value_t *res)
{
msg("myBoschME7xfunc is called with arg0=%x and arg1=%s\n", argv[0].num, argv[1].str);
res->num = 5; // let's return 5
return eOk;
}
//--------------------------------------------------------------------------
// This callback is called for UI notification events
static int idaapi BoschME7x_callback(void * /*user_data*/, int event_id, va_list /*va*/)
{
if ( event_id != ui_msg ) // avoid recursion
if ( event_id != ui_setstate
&& event_id != ui_showauto
&& event_id != ui_refreshmarked ) // ignore uninteresting events
msg("ui_callback %d\n", event_id);
return 0; // 0 means "process the event"
// otherwise the event would be ignored
}
//--------------------------------------------------------------------------
// A sample how to generate user-defined line prefixes
static const int prefix_width = 8;
static void get_user_defined_prefix(ea_t ea,
int lnnum,
int indent,
const char *line,
char *buf,
size_t bufsize)
{
buf[0] = '\0'; // empty prefix by default
// We want to display the prefix only the lines which
// contain the instruction itself
if ( indent != -1 ) return; // a directive
if ( line[0] == '\0' ) return; // empty line
if ( tag_advance(line,1)[-1] == ash.cmnt[0] ) return; // comment line...
// We don't want the prefix to be printed again for other lines of the
// same instruction/data. For that we remember the line number
// and compare it before generating the prefix
static ea_t old_ea = BADADDR;
static int old_lnnum;
if ( old_ea == ea && old_lnnum == lnnum ) return;
// Ok, seems that we found an instruction line.
// Let's display the size of the current item as the user-defined prefix
ulong our_size = get_item_size(ea);
// We don't bother about the width of the prefix
// because it will be padded with spaces by the kernel
qsnprintf(buf, bufsize, " %d", our_size);
// Remember the address and line number we produced the line prefix for:
old_ea = ea;
old_lnnum = lnnum;
}
//--------------------------------------------------------------------------
//
// Initialize.
//
// IDA will call this function only once.
// If this function returns PLGUIN_SKIP, IDA will never load it again.
// If this function returns PLUGIN_OK, IDA will unload the plugin but
// remember that the plugin agreed to work with the database.
// The plugin will be loaded again if the user invokes it by
// pressing the hotkey or selecting it from the menu.
// After the second load the plugin will stay on memory.
// If this function returns PLUGIN_KEEP, IDA will keep the plugin
// in the memory. In this case the initialization function can hook
// into the processor module and user interface notification points.
// See the hook_to_notification_point() function.
//
// In this example we check the input file format and make the decision.
// You may or may not check any other conditions to decide what you do:
// whether you agree to work with the database or not.
//
int idaapi init(void)
{
if ( inf.filetype == f_ELF ) return PLUGIN_SKIP;
// Please uncomment the following line to see how the notification works
// hook_to_notification_point(HT_UI, sample_callback, NULL);
// PLUGIN.flags &= ~PLUGIN_UNL;
// Please uncomment the following line to see how to the user-defined prefix works
// set_user_defined_prefix(prefix_width, get_user_defined_prefix);
// Please uncomment the following line to see how to define IDC functions
// set_idc_func("MyBoschME7xFunc5", myfunc5, myfunc5_args);
const char *options = get_plugin_options("BoschME7x");
if ( options != NULL )
warning("command line options: %s", options);
return (PLUGIN.flags & PLUGIN_UNL) ? PLUGIN_OK : PLUGIN_KEEP;
}
//--------------------------------------------------------------------------
// Terminate.
// Usually this callback is empty.
// The plugin should unhook from the notification lists if
// hook_to_notification_point() was used.
//
// IDA will call this function when the user asks to exit.
// This function won't be called in the case of emergency exits.
void idaapi term(void)
{
unhook_from_notification_point(HT_UI, BoschME7x_callback);
set_user_defined_prefix(0, NULL);
set_idc_func("MyBoschME7xFunc5", NULL, NULL);
}
//--------------------------------------------------------------------------
//
// The plugin method
//
// This is the main function of plugin.
//
// It will be called when the user selects the plugin.
//
// arg - the input argument, it can be specified in
// plugins.cfg file. The default is zero.
//
//
void idaapi run(int arg)
{
msg("*******************\n");
msg("*******************\n");
msg(" BOSCH Diss Helper \n");
msg("*******************\n");
msg("*******************\n");
// if ( inf.filetype != f_PE ) return PLUGIN_SKIP; // only for PE files
// ph.id = PLFM_C166
msg("myBoschME7xfunc - processor is %s, inf.filetype is %d, ph.id is %d\n", inf.procName, inf.filetype, ph.id);
// ExtLinA
// warning("BoschME7x plugin \"line_prefixes\" is called with arg %x\n", arg);
// msg("just fyi: the current screen address is: %a\n", get_screen_ea());
/* if ( !autoIsOk()
&& askyn_c(-1, "HIDECANCEL\n"
"The autoanalysis has not finished yet.\n"
"The result might be incomplete. Do you want to continue?") < 0 )
return;*/
BOOL bNewME711 = FALSE;
if(askyn_c(-1, "HIDECANCEL\n"
"Is this a new Bosch ME7.1.1? (Data table at 0xe00000)") == 1 )
bNewME711 = TRUE;
else
bNewME711 = FALSE;
if(askyn_c(-1, "HIDECANCEL\n"
"Define segments? (WARNING: Will delete your existing disassembly!!!)") == 1 )
{
msg("Calling MakeSegments()\n");
boschcode.MakeSegments(bNewME711);
}
if(askyn_c(-1, "HIDECANCEL\n"
"Find Standard Functions and Comment Them?") == 1 )
{
msg("Calling SearchForFuncSigsAndThenCmt()\n");
boschcode.SearchForFuncSigsAndThenCmt(bNewME711);
}
if(askyn_c(-1, "HIDECANCEL\n"
"Disassemble into code?") == 1 )
{
msg("Calling MakeDissCode()\n");
boschcode.MakeDissCode(bNewME711);
}
if(askyn_c(-1, "HIDECANCEL\n"
"Find DTC Flag Settings?") == 1 )
{
msg("Calling SearchForDTCFlagSetting()\n");
boschcode.SearchForDTCFlagSetting(bNewME711);
}
if(askyn_c(-1, "HIDECANCEL\n"
"Find and Create Offsets?") == 1 )
{
msg("Calling SearchForArrayOffsetsAndThenCreate()\n");
boschcode.SearchForArrayOffsetsAndThenCreate(bNewME711);
}
msg("BoschMe7x Finshed.\n");
}
//--------------------------------------------------------------------------
char comment[] = "BoschME7x - Assists in the disassembly of ME7.x ECUs";
char help[] =
"BoschME7x plugin module\n"
"\n"
"This module assists the user in disassembling Bosch ME7.x ECUs.\n"
"\n"
"It correctly sets up IDA with the ECU addresses and segments. Additionally,\n"
"it auto disassembles and identifies key routines within the binary.\n";
//--------------------------------------------------------------------------
// This is the preferred name of the plugin module in the menu system
// The preferred name may be overriden in plugins.cfg file
char wanted_name[] = "BoschME7x";
// This is the preferred hotkey for the plugin module
// The preferred hotkey may be overriden in plugins.cfg file
// Note: IDA won't tell you if the hotkey is not correct
// It will just disable the hotkey.
char wanted_hotkey[] = "Alt-1";
//--------------------------------------------------------------------------
//
// PLUGIN DESCRIPTION BLOCK
//
//--------------------------------------------------------------------------
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
PLUGIN_UNL, // plugin flags
init, // initialize
term, // terminate. this pointer may be NULL.
run, // invoke plugin
comment, // long comment about the plugin
// it could appear in the status line
// or as a hint
help, // multiline help about the plugin
wanted_name, // the preferred short name of the plugin
wanted_hotkey // the preferred hotkey to run the plugin
};

321
boschme7x.cpp Normal file
View File

@ -0,0 +1,321 @@
/*
* This is a sample plugin module
*
* It can be compiled by any of the supported compilers:
*
* - Borland C++, CBuilder, free C++
* - Watcom C++ for DOS32
* - Watcom C++ for OS/2
* - Visual C++
*
*/
//Standard Defs
typedef int BOOL;
#define FALSE 0
#define TRUE 1
#define NULL 0
#include <ida.hpp>
#include <idp.hpp>
#include <expr.hpp>
#include <loader.hpp>
#include <name.hpp>
//#include <bytes.hpp>
//#include <kernwin.hpp>
//#include <name.hpp>
//#include <offset.hpp>
//#include <search.hpp>
#include "BoschHelper.h"
extern plugin_t PLUGIN;
BoschHelper boschcode; //our class
//--------------------------------------------------------------------------
// Example of a user-defined IDC function in C++
static const char myBoschME7xfunc5_args[] = { VT_LONG, VT_STR, 0 };
static error_t idaapi myfunc5(idc_value_t *argv, idc_value_t *res)
{
msg("myBoschME7xfunc is called with arg0=%x and arg1=%s\n", argv[0].num, argv[1].str);
res->num = 5; // let's return 5
return eOk;
}
//--------------------------------------------------------------------------
// This callback is called for UI notification events
static int idaapi BoschME7x_callback(void * /*user_data*/, int event_id, va_list /*va*/)
{
if ( event_id != ui_msg ) // avoid recursion
if (event_id != ui_obsolete_setstate
&& event_id != ui_obsolete_showauto
&& event_id != ui_refreshmarked ) // ignore uninteresting events
msg("ui_callback %d\n", event_id);
return 0; // 0 means "process the event"
// otherwise the event would be ignored
}
//--------------------------------------------------------------------------
// A sample how to generate user-defined line prefixes
static const int prefix_width = 8;
static void get_user_defined_prefix(ea_t ea,
int lnnum,
int indent,
const char *line,
char *buf,
size_t bufsize)
{
buf[0] = '\0'; // empty prefix by default
// We want to display the prefix only the lines which
// contain the instruction itself
if ( indent != -1 ) return; // a directive
if ( line[0] == '\0' ) return; // empty line
if ( tag_advance(line,1)[-1] == ash.cmnt[0] ) return; // comment line...
// We don't want the prefix to be printed again for other lines of the
// same instruction/data. For that we remember the line number
// and compare it before generating the prefix
static ea_t old_ea = BADADDR;
static int old_lnnum;
if ( old_ea == ea && old_lnnum == lnnum ) return;
// Ok, seems that we found an instruction line.
// Let's display the size of the current item as the user-defined prefix
ulong our_size = get_item_size(ea);
// We don't bother about the width of the prefix
// because it will be padded with spaces by the kernel
qsnprintf(buf, bufsize, " %d", our_size);
// Remember the address and line number we produced the line prefix for:
old_ea = ea;
old_lnnum = lnnum;
}
//--------------------------------------------------------------------------
//
// Initialize.
//
// IDA will call this function only once.
// If this function returns PLGUIN_SKIP, IDA will never load it again.
// If this function returns PLUGIN_OK, IDA will unload the plugin but
// remember that the plugin agreed to work with the database.
// The plugin will be loaded again if the user invokes it by
// pressing the hotkey or selecting it from the menu.
// After the second load the plugin will stay on memory.
// If this function returns PLUGIN_KEEP, IDA will keep the plugin
// in the memory. In this case the initialization function can hook
// into the processor module and user interface notification points.
// See the hook_to_notification_point() function.
//
// In this example we check the input file format and make the decision.
// You may or may not check any other conditions to decide what you do:
// whether you agree to work with the database or not.
//
int idaapi init(void)
{
if ( inf.filetype == f_ELF ) return PLUGIN_SKIP;
// Please uncomment the following line to see how the notification works
// hook_to_notification_point(HT_UI, sample_callback, NULL);
// PLUGIN.flags &= ~PLUGIN_UNL;
// Please uncomment the following line to see how to the user-defined prefix works
// set_user_defined_prefix(prefix_width, get_user_defined_prefix);
// Please uncomment the following line to see how to define IDC functions
// set_idc_func("MyBoschME7xFunc5", myfunc5, myfunc5_args);
const char *options = get_plugin_options("BoschME7x");
if ( options != NULL )
warning("command line options: %s", options);
return (PLUGIN.flags & PLUGIN_UNL) ? PLUGIN_OK : PLUGIN_KEEP;
}
//--------------------------------------------------------------------------
// Terminate.
// Usually this callback is empty.
// The plugin should unhook from the notification lists if
// hook_to_notification_point() was used.
//
// IDA will call this function when the user asks to exit.
// This function won't be called in the case of emergency exits.
void idaapi term(void)
{
unhook_from_notification_point(HT_UI, BoschME7x_callback);
set_user_defined_prefix(0, NULL);
set_idc_func_ex("MyBoschME7xFunc5", NULL, NULL, 0);
}
//--------------------------------------------------------------------------
//
// The plugin method
//
// This is the main function of plugin.
//
// It will be called when the user selects the plugin.
//
// arg - the input argument, it can be specified in
// plugins.cfg file. The default is zero.
//
//
void idaapi run(int arg)
{
unsigned short BOSCH = 0x01;
unsigned short newBosch = 0x01;
unsigned short defSegs = 0x02;
unsigned short findSandFuncs =0x04;
unsigned short DissAsm = 0x08;
unsigned short findDTC =0x10;
unsigned short createOffsets=0x20;
unsigned short cfg_box_2_answer=0x00;
char label[MAXSTR] = "";
BOOL bNewME711 = FALSE;
static const char cfg_box_2 []=
"Select your option for BOSCH Processor\n"
"<Is this a new Bosch ME7.1.1? (Data table at 0xe00000):C>\n"
"<Define segments? (WARNING this Will delete your existing disassembly!!!):C>\n"
"<Find Standard Functions and Comment Them?:C >\n"
"<Disassemble into asm code :C>\n"
"<Find DTC Flag Settings:C>\n"
"<Find and Create Offsets:C>>\n";
if (BOSCH)
{
if (! AskUsingForm_c(cfg_box_2, &cfg_box_2_answer) )
{
return;
}
}
// if ( inf.filetype != f_PE ) return PLUGIN_SKIP; // only for PE files
// ph.id = PLFM_C166
msg("myBoschME7xfunc - processor is %s, inf.filetype is %d, ph.id is %d\n", inf.procName, inf.filetype, ph.id);
msg("just fyi: the current screen address is: %a\n", get_screen_ea());
msg("newBosch =x%x\n ",newBosch);
// if ( !autoIsOk()&& askyn_c(-1, "HIDECANCEL\n"
// "The autoanalysis has not finished yet.\n"
// "The result might be incomplete. Do you want to continue?") < 0 )//
// return;
if(newBosch & cfg_box_2_answer)
bNewME711 = TRUE;
else
bNewME711 = FALSE;
using namespace std;
string sECU = "";
if (bNewME711)
{
sECU = "bNewME711";
//sECU ="ME761Astra";
msg("ME711\n");
}
if (defSegs & cfg_box_2_answer)
{
msg("Calling MakeSegments()\n");
boschcode.MakeSegments(sECU);
}
if(findSandFuncs & cfg_box_2_answer)
{
msg("Calling SearchForFuncSigsAndThenCmt()\n");
boschcode.SearchForFuncSigsAndThenCmt(sECU);
}
if(DissAsm & cfg_box_2_answer)
{
msg("Calling MakeDissCode()\n");
boschcode.MakeDissCode(sECU);
}
if (findDTC & cfg_box_2_answer)
{
msg("Calling SearchForDTCFlagSetting()\n");
boschcode.SearchForDTCFlagSetting(sECU);
}
if (createOffsets & cfg_box_2_answer)
{
msg("Calling SearchForArrayOffsetsAndThenCreate()\n");
boschcode.SearchForArrayOffsetsAndThenCreate(sECU);
}
msg("BoschMe7x finished.\n");
}
//--------------------------------------------------------------------------
char comment[] = "BoschME7x v2.1 - Assists in the disassembly of ME7.x ECUs";
char help[] =
"BoschME7x plugin module\n"
"\n"
"This module assists the user in disassembling Bosch ME7.x ECUs.\n"
"\n"
"It correctly sets up IDA with the ECU addresses and segments. Additionally,\n"
"it auto disassembles and identifies key routines within the binary.\n";
//--------------------------------------------------------------------------
// This is the preferred name of the plugin module in the menu system
// The preferred name may be overriden in plugins.cfg file
char wanted_name[] = "BoschME7x";
// This is the preferred hotkey for the plugin module
// The preferred hotkey may be overriden in plugins.cfg file
// Note: IDA won't tell you if the hotkey is not correct
// It will just disable the hotkey.
char wanted_hotkey[] = "Alt-1";
//--------------------------------------------------------------------------
//
// PLUGIN DESCRIPTION BLOCK
//
//--------------------------------------------------------------------------
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
PLUGIN_UNL, // plugin flags
init, // initialize
term, // terminate. this pointer may be NULL.
run, // invoke plugin
comment, // long comment about the plugin
// it could appear in the status line
// or as a hint
help, // multiline help about the plugin
wanted_name, // the preferred short name of the plugin
wanted_hotkey // the preferred hotkey to run the plugin
};

20
boschme7x.sln Normal file
View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "boschme7x", "boschme7x.vcxproj", "{8FA89F4D-EBA9-4BDB-97AF-556FAC926BE9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8FA89F4D-EBA9-4BDB-97AF-556FAC926BE9}.Debug|Win32.ActiveCfg = Debug|Win32
{8FA89F4D-EBA9-4BDB-97AF-556FAC926BE9}.Debug|Win32.Build.0 = Debug|Win32
{8FA89F4D-EBA9-4BDB-97AF-556FAC926BE9}.Release|Win32.ActiveCfg = Release|Win32
{8FA89F4D-EBA9-4BDB-97AF-556FAC926BE9}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

342
boschme7x.vcproj Normal file
View File

@ -0,0 +1,342 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="boschme7x"
ProjectGUID="{8FA89F4D-EBA9-4BDB-97AF-556FAC926BE9}"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Release/boschme7x.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_USRDLL;__NT__;__IDP__;MAXSTR=1024"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release/boschme7x.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="true"
CallingConvention="2"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="2057"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/export:PLUGIN"
AdditionalDependencies="odbc32.lib odbccp32.lib ida.lib"
OutputFile="../../../plugins/boschme7x.plw"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\lib\vc.w32"
ProgramDatabaseFile=".\Release/boschme7x.pdb"
ImportLibrary=".\Release/boschme7x.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/boschme7x.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Debug/boschme7x.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="_DEBUG;__NT__;__IDP__;MAXSTR=1024;WIN32;_WINDOWS;_USRDLL"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug/boschme7x.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="3"
CallingConvention="2"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="2057"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/export:PLUGIN"
AdditionalDependencies="ida.lib odbc32.lib odbccp32.lib"
OutputFile="../../../plugins/boschme7x.plw"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\lib\vc.w32"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\Debug/boschme7x.pdb"
GenerateMapFile="true"
MapFileName=".\Debug/boschme7x.map"
ImportLibrary=".\Debug/boschme7x.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug/boschme7x.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="BoschHelper.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\boschme7x.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="__WIN32__"
/>
</FileConfiguration>
</File>
<File
RelativePath="FunctionSigs.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="IDAMemCopyPaste.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="BoschHelper.h"
>
</File>
<File
RelativePath="FunctionSigs.h"
>
</File>
<File
RelativePath="IDAMemCopyPaste.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
<File
RelativePath="Me71 1024K Search without prompts.idc"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

194
boschme7x.vcxproj Normal file
View File

@ -0,0 +1,194 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8FA89F4D-EBA9-4BDB-97AF-556FAC926BE9}</ProjectGuid>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\Release\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\Debug\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.plw</TargetExt>
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.plw</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>true</MkTypLibCompatible>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TargetEnvironment>Win32</TargetEnvironment>
<TypeLibraryName>.\Release/boschme7x.tlb</TypeLibraryName>
<HeaderFileName>
</HeaderFileName>
</Midl>
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>C:\Ida\sdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;_USRDLL;__NT__;__IDP__;MAXSTR=1024;%(PreprocessorDefinitions);__NT__;__IDP__</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeaderOutputFile>.\Release/boschme7x.pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\Release/</AssemblerListingLocation>
<ObjectFileName>.\Release/</ObjectFileName>
<ProgramDataBaseFileName>.\Release/</ProgramDataBaseFileName>
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<CallingConvention>StdCall</CallingConvention>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0809</Culture>
</ResourceCompile>
<Link>
<AdditionalOptions>/export:PLUGIN %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>odbc32.lib;odbccp32.lib;ida.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>C:\Ida\sdk\lib\x86_win_vc_32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ProgramDatabaseFile>.\Release/boschme7x.pdb</ProgramDatabaseFile>
<ImportLibrary>.\Release/boschme7x.lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<OutputFile>c:/ida/plugins/boschme7x.plw</OutputFile>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
<OutputFile>.\Release/boschme7x.bsc</OutputFile>
</Bscmake>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>true</MkTypLibCompatible>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TargetEnvironment>Win32</TargetEnvironment>
<TypeLibraryName>.\Debug/boschme7x.tlb</TypeLibraryName>
<HeaderFileName>
</HeaderFileName>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>C:\Ida\sdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;__NT__;__IDP__;MAXSTR=1024;WIN32;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);__NT__;__IDP__</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeaderOutputFile>.\Debug/boschme7x.pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\Debug/</AssemblerListingLocation>
<ObjectFileName>.\Debug/</ObjectFileName>
<ProgramDataBaseFileName>.\Debug/</ProgramDataBaseFileName>
<BrowseInformation>true</BrowseInformation>
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CallingConvention>StdCall</CallingConvention>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0809</Culture>
</ResourceCompile>
<Link>
<AdditionalOptions>/export:PLUGIN %(AdditionalOptions)</AdditionalOptions>
<OutputFile>c:/ida/plugins/boschme7x.plw</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>C:\Ida\sdk\lib\x86_win_vc_32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>.\Debug/boschme7x.pdb</ProgramDatabaseFile>
<GenerateMapFile>true</GenerateMapFile>
<MapFileName>.\Debug/boschme7x.map</MapFileName>
<ImportLibrary>.\Debug/boschme7x.lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
<OutputFile>.\Debug/boschme7x.bsc</OutputFile>
</Bscmake>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="BoschHelper.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="boschme7x.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">__WIN32__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="FunctionSigs.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="IDAMemCopyPaste.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BoschHelper.h" />
<ClInclude Include="FunctionSigs.h" />
<ClInclude Include="IDAMemCopyPaste.h" />
</ItemGroup>
<ItemGroup>
<None Include="Me71 1024K Search without prompts.idc" />
</ItemGroup>
<ItemGroup>
<Library Include="..\..\lib\x86_win_vc_32\ida.lib" />
<Library Include="..\..\lib\x86_win_vc_32\pro.lib" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

53
boschme7x.vcxproj.filters Normal file
View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{b0f223cb-dc9b-4f9a-9765-3d4f29af7c2c}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{3719e080-c770-49cf-877f-bb4083d7bfa3}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{432ca54f-4095-434d-8755-771812a284a4}</UniqueIdentifier>
<Extensions>ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BoschHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="boschme7x.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="FunctionSigs.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IDAMemCopyPaste.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BoschHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FunctionSigs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IDAMemCopyPaste.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Me71 1024K Search without prompts.idc" />
</ItemGroup>
<ItemGroup>
<Library Include="..\..\lib\x86_win_vc_32\ida.lib">
<Filter>Source Files</Filter>
</Library>
<Library Include="..\..\lib\x86_win_vc_32\pro.lib">
<Filter>Source Files</Filter>
</Library>
</ItemGroup>
</Project>

254
findcrypt.cpp Normal file
View File

@ -0,0 +1,254 @@
// FindCrypt - find constants used in crypto algorithms
// Copyright 2006 Ilfak Guilfanov <ig@hexblog.com>
// This is a freeware program.
// This copytight message must be kept intact.
// This plugin looks for constant arrays used in popular crypto algorithms.
// If a crypto algorithm is found, it will rename the appropriate locations
// of the program and put bookmarks on them.
// Version 2.0
#include <ida.hpp>
#include <idp.hpp>
#include <loader.hpp>
#include <kernwin.hpp>
#include <bytes.hpp>
#include <name.hpp>
#include <moves.hpp>
#include <auto.hpp>
#include <set>
#include "findcrypt.hpp"
//--------------------------------------------------------------------------
// retrieve the first byte of the specified array
// take into account the byte sex
inline uchar get_first_byte(const array_info_t *a)
{
const uchar *ptr = (const uchar *)a->array;
if ( !inf.mf )
return ptr[0];
return ptr[a->elsize-1];
}
//--------------------------------------------------------------------------
// check that all constant arrays are distinct (no duplicates)
//lint -e528 not used
static void verify_constants(const array_info_t *consts)
{
typedef std::set<qstring> strset_t;
strset_t myset;
for ( const array_info_t *ptr=consts; ptr->size != 0; ptr++ )
{
qstring s((char*)ptr->array, ptr->size);
if ( !myset.insert(s).second )
error("duplicate array %s!", ptr->name);
}
}
//--------------------------------------------------------------------------
// match a constant array against the database at the specified address
static bool match_array_pattern(ea_t ea, const array_info_t *ai)
{
uchar *ptr = (uchar *)ai->array;
for ( size_t i=0; i < ai->size; i++ )
{
switch ( ai->elsize )
{
case 1:
if ( get_byte(ea) != *(uchar*)ptr )
return false;
break;
case 2:
if ( get_word(ea) != *(ushort*)ptr )
return false;
break;
case 4:
if ( get_long(ea) != *(uint32*)ptr )
return false;
break;
case 8:
if ( get_qword(ea)!= *(uint64*)ptr )
return false;
break;
default:
error("interr: unexpected array '%s' element size %d",
ai->name, ai->elsize);
}
ptr += ai->elsize;
ea += ai->elsize;
}
return true;
}
//--------------------------------------------------------------------------
// match a sparse array against the database at the specified address
// NB: all sparse arrays must be word32!
static bool match_sparse_pattern(ea_t ea, const array_info_t *ai)
{
const word32 *ptr = (const word32*)ai->array;
if ( get_long(ea) != *ptr++ )
return false;
ea += 4;
for ( size_t i=1; i < ai->size; i++ )
{
word32 c = *ptr++;
if ( inf.mf )
c = swap32(c);
// look for the constant in the next N bytes
const size_t N = 64;
uchar mem[N+4];
get_many_bytes(ea, mem, sizeof(mem));
int j;
for ( j=0; j < N; j++ )
if ( *(uint32*)(mem+j) == c )
break;
if ( j == N )
return false;
ea += j + 4;
}
return true;
}
//--------------------------------------------------------------------------
// mark a location with the name of the algorithm
// use the first free slot for the marker
static void mark_location(ea_t ea, const char *name)
{
char buf[MAXSTR];
curloc cl;
cl.ea = ea;
cl.target = ea;
cl.x = 0;
cl.y = 5;
cl.lnnum = 0;
cl.flags = 0;
// find free marked location slot
int i;
for ( i=1; i <= MAX_MARK_SLOT; i++ )
{
if ( cl.markdesc(i, buf, sizeof(buf)) <= 0 )
break;
// reuse old "Crypto: " slots
if ( strncmp(buf, "Crypto: ", 7) == 0 && cl.markedpos(&i) == ea )
break;
}
if ( i <= MAX_MARK_SLOT )
{
qsnprintf(buf, sizeof(buf), "Crypto: %s", name);
cl.mark(i, NULL, buf);
}
}
//--------------------------------------------------------------------------
// try to find constants at the given address range
static void recognize_constants(ea_t ea1, ea_t ea2)
{
int count = 0;
show_wait_box("Searching for crypto constants...");
for ( ea_t ea=ea1; ea < ea2; ea=nextaddr(ea) )
{
if ( (ea % 0x1000) == 0 )
{
showAddr(ea);
if ( wasBreak() )
break;
}
uchar b = get_byte(ea);
// check against normal constants
for ( const array_info_t *ptr=non_sparse_consts; ptr->size != 0; ptr++ )
{
if ( b != get_first_byte(ptr) )
continue;
if ( match_array_pattern(ea, ptr) )
{
msg("%a: found const array %s (used in %s)\n", ea, ptr->name, ptr->algorithm);
mark_location(ea, ptr->algorithm);
do_name_anyway(ea, ptr->name);
count++;
break;
}
}
// check against sparse constants
for ( const array_info_t *ptr=sparse_consts; ptr->size != 0; ptr++ )
{
if ( b != get_first_byte(ptr) )
continue;
if ( match_sparse_pattern(ea, ptr) )
{
msg("%a: found sparse constants for %s\n", ea, ptr->algorithm);
mark_location(ea, ptr->algorithm);
count++;
break;
}
}
}
hide_wait_box();
if ( count != 0 )
msg("Found %d known constant arrays in total.\n", count);
}
//--------------------------------------------------------------------------
// This callback is called for IDP notification events
static int idaapi search_callback(void * /*user_data*/, int event_id, va_list /*va*/)
{
if ( event_id == processor_t::newfile ) // A new file is loaded (already)
recognize_constants(inf.minEA, inf.maxEA);
return 0;
}
//--------------------------------------------------------------------------
void idaapi run(int)
{
ea_t ea1, ea2;
read_selection(&ea1, &ea2); // if fails, inf.minEA and inf.maxEA will be used
recognize_constants(ea1, ea2);
}
//--------------------------------------------------------------------------
int idaapi init(void)
{
// verify_constants(non_sparse_consts);
// verify_constants(sparse_consts);
// agree to work with any database
hook_to_notification_point(HT_IDP, search_callback, NULL);
return PLUGIN_KEEP;
}
//--------------------------------------------------------------------------
void idaapi term(void)
{
unhook_from_notification_point(HT_IDP, search_callback, NULL);
}
//--------------------------------------------------------------------------
static const char help[] = "Find crypt v2";
static const char comment[] = "Find crypt v2";
static const char wanted_name[] = "Find crypt v2";
static const char wanted_hotkey[] = "";
//--------------------------------------------------------------------------
//
// PLUGIN DESCRIPTION BLOCK
//
//--------------------------------------------------------------------------
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
PLUGIN_PROC, // plugin flags
init, // initialize
term, // terminate. this pointer may be NULL.
run, // invoke plugin
comment, // long comment about the plugin
// it could appear in the status line
// or as a hint
help, // multiline help about the plugin
wanted_name, // the preferred short name of the plugin
wanted_hotkey // the preferred hotkey to run the plugin
};

9
makefile Normal file
View File

@ -0,0 +1,9 @@
PROC=boschme7x
!include ..\plugin.mak
# MAKEDEP dependency list ------------------
$(F)boschme7x$(O) : $(I)area.hpp $(I)bytes.hpp $(I)expr.hpp $(I)fpro.h \
$(I)funcs.hpp $(I)help.h $(I)ida.hpp $(I)idp.hpp \
$(I)kernwin.hpp $(I)lines.hpp $(I)llong.hpp \
$(I)loader.hpp $(I)nalt.hpp $(I)netnode.hpp $(I)pro.h \
$(I)segment.hpp $(I)ua.hpp $(I)xref.hpp boschme7x.cpp

9
makefile.gcc Normal file
View File

@ -0,0 +1,9 @@
PROC=boschme7x
include ../plugin.gcc.mak
# MAKEDEP dependency list ------------------
$(F)boschme7x$(O): $(I)area.hpp $(I)bytes.hpp $(I)fpro.h $(I)funcs.hpp \
$(I)help.h $(I)ida.hpp $(I)idp.hpp $(I)kernwin.hpp \
$(I)lines.hpp $(I)llong.hpp $(I)loader.hpp $(I)nalt.hpp \
$(I)netnode.hpp $(I)pro.h $(I)segment.hpp $(I)ua.hpp \
$(I)xref.hpp boschme7x.cpp

9
makefile.vc Normal file
View File

@ -0,0 +1,9 @@
PROC=boschme7x
!include ..\plugin.vc.mak
# MAKEDEP dependency list ------------------
$(F)boschme7x$(O): $(I)area.hpp $(I)bytes.hpp $(I)fpro.h $(I)funcs.hpp \
$(I)help.h $(I)ida.hpp $(I)idp.hpp $(I)kernwin.hpp \
$(I)lines.hpp $(I)llong.hpp $(I)loader.hpp $(I)nalt.hpp \
$(I)netnode.hpp $(I)pro.h $(I)segment.hpp $(I)ua.hpp \
$(I)xref.hpp boschme7x.cpp

733
stdio.h Normal file
View File

@ -0,0 +1,733 @@
/***
*stdio.h - definitions/declarations for standard I/O routines
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* This file defines the structures, values, macros, and functions
* used by the level 2 I/O ("standard I/O") routines.
* [ANSI/System V]
*
* [Public]
*
****/
#pragma once
#ifndef _INC_STDIO
#define _INC_STDIO
#include <crtdefs.h>
/*
* Currently, all MS C compilers for Win32 platforms default to 8 byte
* alignment.
*/
#pragma pack(push,_CRT_PACKING)
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Buffered I/O macros */
#define BUFSIZ 512
#ifdef _CRTBLD
/*
* Real default size for stdio buffers
*/
#define _INTERNAL_BUFSIZ 4096
#define _SMALL_BUFSIZ 512
#endif /* _CRTBLD */
/*
* Default number of supported streams. _NFILE is confusing and obsolete, but
* supported anyway for backwards compatibility.
*/
#define _NFILE _NSTREAM_
#define _NSTREAM_ 512
/*
* Number of entries in _iob[] (declared below). Note that _NSTREAM_ must be
* greater than or equal to _IOB_ENTRIES.
*/
#define _IOB_ENTRIES 20
#define EOF (-1)
#ifndef _FILE_DEFINED
struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char *_tmpfname;
};
typedef struct _iobuf FILE;
#define _FILE_DEFINED
#endif /* _FILE_DEFINED */
/* Directory where temporary files may be created. */
#define _P_tmpdir "\\"
#define _wP_tmpdir L"\\"
/* L_tmpnam = length of string _P_tmpdir
* + 1 if _P_tmpdir does not end in "/" or "\", else 0
* + 12 (for the filename string)
* + 1 (for the null terminator)
* L_tmpnam_s = length of string _P_tmpdir
* + 1 if _P_tmpdir does not end in "/" or "\", else 0
* + 16 (for the filename string)
* + 1 (for the null terminator)
*/
#define L_tmpnam (sizeof(_P_tmpdir) + 12)
#if __STDC_WANT_SECURE_LIB__
#define L_tmpnam_s (sizeof(_P_tmpdir) + 16)
#endif /* __STDC_WANT_SECURE_LIB__ */
/* Seek method constants */
#define SEEK_CUR 1
#define SEEK_END 2
#define SEEK_SET 0
#define FILENAME_MAX 260
#define FOPEN_MAX 20
#define _SYS_OPEN 20
#define TMP_MAX 32767 /* SHRT_MAX */
#if __STDC_WANT_SECURE_LIB__
#define TMP_MAX_S _TMP_MAX_S
#define _TMP_MAX_S 2147483647 /* INT_MAX */
#endif /* __STDC_WANT_SECURE_LIB__ */
/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else /* __cplusplus */
#define NULL ((void *)0)
#endif /* __cplusplus */
#endif /* NULL */
/* Declare _iob[] array */
#ifndef _STDIO_DEFINED
#ifdef _CRTBLD
/* These functions are for enabling STATIC_CPPLIB functionality */
#if defined (_DLL) && defined (_M_IX86)
/* Retained for compatibility with VC++ 5.0 and earlier versions */
_CRTIMP extern FILE * __cdecl __p__iob(void);
#endif /* defined (_DLL) && defined (_M_IX86) */
#ifndef _M_CEE_PURE
_CRTIMP extern FILE _iob[];
#endif /* _M_CEE_PURE */
#endif /* _CRTBLD */
_CRTIMP FILE * __cdecl __iob_func(void);
#endif /* _STDIO_DEFINED */
/* Define file position type */
#ifndef _FPOS_T_DEFINED
typedef __int64 fpos_t;
#define _FPOS_T_DEFINED
#endif /* _FPOS_T_DEFINED */
#ifndef _STDSTREAM_DEFINED
#define stdin (&__iob_func()[0])
#define stdout (&__iob_func()[1])
#define stderr (&__iob_func()[2])
#define _STDSTREAM_DEFINED
#endif /* _STDSTREAM_DEFINED */
#define _IOREAD 0x0001
#define _IOWRT 0x0002
#define _IOFBF 0x0000
#define _IOLBF 0x0040
#define _IONBF 0x0004
#define _IOMYBUF 0x0008
#define _IOEOF 0x0010
#define _IOERR 0x0020
#define _IOSTRG 0x0040
#define _IORW 0x0080
/* constants used by _set_output_format */
#define _TWO_DIGIT_EXPONENT 0x1
/* Function prototypes */
#ifndef _STDIO_DEFINED
_Check_return_ _CRTIMP int __cdecl _filbuf(_Inout_ FILE * _File );
_Check_return_opt_ _CRTIMP int __cdecl _flsbuf(_In_ int _Ch, _Inout_ FILE * _File);
_Check_return_ _CRTIMP FILE * __cdecl _fsopen(_In_z_ const char * _Filename, _In_z_ const char * _Mode, _In_ int _ShFlag);
_CRTIMP void __cdecl clearerr(_Inout_ FILE * _File);
#if __STDC_WANT_SECURE_LIB__
_Check_return_wat_ _CRTIMP errno_t __cdecl clearerr_s(_Inout_ FILE * _File );
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _fcloseall(void);
_Check_return_ _CRTIMP FILE * __cdecl _fdopen(_In_ int _FileHandle, _In_z_ const char * _Mode);
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE * _File);
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _fgetchar(void);
_Check_return_opt_ _CRTIMP int __cdecl fgetpos(_Inout_ FILE * _File , _Out_ fpos_t * _Pos);
_Check_return_opt_ _CRTIMP char * __cdecl fgets(_Out_writes_z_(_MaxCount) char * _Buf, _In_ int _MaxCount, _Inout_ FILE * _File);
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE * _File);
#if defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC)
#pragma push_macro("_tempnam")
#undef _tempnam
#endif /* defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC) */
_Check_return_ _CRTIMP char * __cdecl _tempnam(_In_opt_z_ const char * _DirName, _In_opt_z_ const char * _FilePrefix);
#if defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_tempnam")
#endif /* defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC) */
_Check_return_opt_ _CRTIMP int __cdecl _flushall(void);
_Check_return_ _CRT_INSECURE_DEPRECATE(fopen_s) _CRTIMP FILE * __cdecl fopen(_In_z_ const char * _Filename, _In_z_ const char * _Mode);
#if __STDC_WANT_SECURE_LIB__
_Check_return_wat_ _CRTIMP errno_t __cdecl fopen_s(_Outptr_result_maybenull_ FILE ** _File, _In_z_ const char * _Filename, _In_z_ const char * _Mode);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const char * _Format, ...);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl fprintf_s(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const char * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl fputc(_In_ int _Ch, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _fputchar(_In_ int _Ch);
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char * _Str, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize*_Count) void * _DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE * _File);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP size_t __cdecl fread_s(_Out_writes_bytes_(_ElementSize*_Count) void * _DstBuf, _In_ size_t _DstSize, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE * _File);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_ _CRT_INSECURE_DEPRECATE(freopen_s) _CRTIMP FILE * __cdecl freopen(_In_z_ const char * _Filename, _In_z_ const char * _Mode, _Inout_ FILE * _File);
#if __STDC_WANT_SECURE_LIB__
_Check_return_wat_ _CRTIMP errno_t __cdecl freopen_s(_Outptr_result_maybenull_ FILE ** _File, _In_z_ const char * _Filename, _In_z_ const char * _Mode, _Inout_ FILE * _OldFile);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_ _CRT_INSECURE_DEPRECATE(fscanf_s) _CRTIMP int __cdecl fscanf(_Inout_ FILE * _File, _In_z_ _Scanf_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_fscanf_s_l) _CRTIMP int __cdecl _fscanf_l(_Inout_ FILE * _File, _In_z_ _Scanf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
#pragma warning(push)
#pragma warning(disable:6530)
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl fscanf_s(_Inout_ FILE * _File, _In_z_ _Scanf_s_format_string_ const char * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl _fscanf_s_l(_Inout_ FILE * _File, _In_z_ _Scanf_s_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
#pragma warning(pop)
_Check_return_opt_ _CRTIMP int __cdecl fsetpos(_Inout_ FILE * _File, _In_ const fpos_t * _Pos);
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE * _File, _In_ long _Offset, _In_ int _Origin);
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _fseeki64(_Inout_ FILE * _File, _In_ __int64 _Offset, _In_ int _Origin);
_Check_return_ _CRTIMP __int64 __cdecl _ftelli64(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size*_Count) const void * _Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE * _File);
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE * _File);
_Check_return_ _CRTIMP int __cdecl getchar(void);
_Check_return_ _CRTIMP int __cdecl _getmaxstdio(void);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP char * __cdecl gets_s(_Out_writes_z_(_Size) char * _Buf, _In_ rsize_t _Size);
#endif /* __STDC_WANT_SECURE_LIB__ */
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(char *, gets_s, char, _Buffer)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(char *, __RETURN_POLICY_SAME, _CRTIMP, gets, _Pre_notnull_ _Post_z_ _Out_writes_z_(((size_t)-1)), char, _Buffer)
_Check_return_ int __cdecl _getw(_Inout_ FILE * _File);
#ifndef _CRT_PERROR_DEFINED
#define _CRT_PERROR_DEFINED
_CRTIMP void __cdecl perror(_In_opt_z_ const char * _ErrMsg);
#endif /* _CRT_PERROR_DEFINED */
#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
_Check_return_opt_ _CRTIMP int __cdecl _pclose(_Inout_ FILE * _File);
_Check_return_ _CRTIMP FILE * __cdecl _popen(_In_z_ const char * _Command, _In_z_ const char * _Mode);
#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP */
_Check_return_opt_ _CRTIMP int __cdecl printf(_In_z_ _Printf_format_string_ const char * _Format, ...);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl printf_s(_In_z_ _Printf_format_string_ const char * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl putc(_In_ int _Ch, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl putchar(_In_ int _Ch);
_Check_return_opt_ _CRTIMP int __cdecl puts(_In_z_ const char * _Str);
_Check_return_opt_ _CRTIMP int __cdecl _putw(_In_ int _Word, _Inout_ FILE * _File);
#ifndef _CRT_DIRECTORY_DEFINED
#define _CRT_DIRECTORY_DEFINED
_CRTIMP int __cdecl remove(_In_z_ const char * _Filename);
_Check_return_ _CRTIMP int __cdecl rename(_In_z_ const char * _OldFilename, _In_z_ const char * _NewFilename);
_CRTIMP int __cdecl _unlink(_In_z_ const char * _Filename);
#if !__STDC__
_CRT_NONSTDC_DEPRECATE(_unlink) _CRTIMP int __cdecl unlink(_In_z_ const char * _Filename);
#endif /* !__STDC__ */
#endif /* _CRT_DIRECTORY_DEFINED */
_CRTIMP void __cdecl rewind(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _rmtmp(void);
_Check_return_ _CRT_INSECURE_DEPRECATE(scanf_s) _CRTIMP int __cdecl scanf(_In_z_ _Scanf_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_scanf_s_l) _CRTIMP int __cdecl _scanf_l(_In_z_ _Scanf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
#pragma warning(push)
#pragma warning(disable:6530)
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl scanf_s(_In_z_ _Scanf_s_format_string_ const char * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _scanf_s_l(_In_z_ _Scanf_s_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
#pragma warning(pop)
_CRT_INSECURE_DEPRECATE(setvbuf) _CRTIMP void __cdecl setbuf(_Inout_ FILE * _File, _Inout_updates_opt_(BUFSIZ) _Post_readable_size_(0) char * _Buffer);
_Check_return_opt_ _CRTIMP int __cdecl _setmaxstdio(_In_ int _Max);
_Check_return_opt_ _CRTIMP unsigned int __cdecl _set_output_format(_In_ unsigned int _Format);
_Check_return_opt_ _CRTIMP unsigned int __cdecl _get_output_format(void);
_Check_return_opt_ _CRTIMP int __cdecl setvbuf(_Inout_ FILE * _File, _Inout_updates_opt_z_(_Size) char * _Buf, _In_ int _Mode, _In_ size_t _Size);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _snprintf_s(_Out_writes_z_(_SizeInBytes) char * _DstBuf, _In_ size_t _SizeInBytes, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const char * _Format, ...);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2_ARGLIST(int, _snprintf_s, _vsnprintf_s, _Post_z_ char, _Dest, _In_ size_t, _MaxCount, _In_z_ _Printf_format_string_ const char *,_Format)
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl sprintf_s(_Out_writes_z_(_SizeInBytes) char * _DstBuf, _In_ size_t _SizeInBytes, _In_z_ _Printf_format_string_ const char * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1_ARGLIST(int, sprintf_s, vsprintf_s, _Post_z_ char, _Dest, _In_z_ _Printf_format_string_ const char *, _Format)
_Check_return_ _CRTIMP int __cdecl _scprintf(_In_z_ _Printf_format_string_ const char * _Format, ...);
_Check_return_ _CRT_INSECURE_DEPRECATE(sscanf_s) _CRTIMP int __cdecl sscanf(_In_z_ const char * _Src, _In_z_ _Scanf_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_sscanf_s_l) _CRTIMP int __cdecl _sscanf_l(_In_z_ const char * _Src, _In_z_ _Scanf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
#pragma warning(push)
#pragma warning(disable:6530)
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl sscanf_s(_In_z_ const char * _Src, _In_z_ _Scanf_s_format_string_ const char * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _sscanf_s_l(_In_z_ const char * _Src, _In_z_ _Scanf_s_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_snscanf_s) _CRTIMP int __cdecl _snscanf(_In_reads_bytes_(_MaxCount) _Pre_z_ const char * _Src, _In_ size_t _MaxCount, _In_z_ _Scanf_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_snscanf_s_l) _CRTIMP int __cdecl _snscanf_l(_In_reads_bytes_(_MaxCount) _Pre_z_ const char * _Src, _In_ size_t _MaxCount, _In_z_ _Scanf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _snscanf_s(_In_reads_bytes_(_MaxCount) _Pre_z_ const char * _Src, _In_ size_t _MaxCount, _In_z_ _Scanf_s_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _snscanf_s_l(_In_reads_bytes_(_MaxCount) _Pre_z_ const char * _Src, _In_ size_t _MaxCount, _In_z_ _Scanf_s_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
#pragma warning(pop)
_Check_return_ _CRT_INSECURE_DEPRECATE(tmpfile_s) _CRTIMP FILE * __cdecl tmpfile(void);
#if __STDC_WANT_SECURE_LIB__
_Check_return_wat_ _CRTIMP errno_t __cdecl tmpfile_s(_Out_opt_ _Deref_post_valid_ FILE ** _File);
_Check_return_wat_ _CRTIMP errno_t __cdecl tmpnam_s(_Out_writes_z_(_Size) char * _Buf, _In_ rsize_t _Size);
#endif /* __STDC_WANT_SECURE_LIB__ */
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, tmpnam_s, _Post_z_ char, _Buf)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(char *, __RETURN_POLICY_DST, _CRTIMP, tmpnam, _Pre_maybenull_ _Post_z_, char, _Buffer)
_Check_return_opt_ _CRTIMP int __cdecl ungetc(_In_ int _Ch, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl vfscanf(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl vfprintf_s(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl vfscanf_s(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl vprintf(_In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl vscanf(_In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl vprintf_s(_In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl vscanf_s(_In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(vsnprintf_s) _CRTIMP int __cdecl vsnprintf(_Out_writes_(_MaxCount) char * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl vsnprintf_s(_Out_writes_z_(_DstSize) char * _DstBuf, _In_ size_t _DstSize, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_3(int, vsnprintf_s, _Post_z_ char, _Dest, _In_ size_t, _MaxCount, _In_z_ _Printf_format_string_ const char *, _Format, va_list, _Args)
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _vsnprintf_s(_Out_writes_z_(_SizeInBytes) char * _DstBuf, _In_ size_t _SizeInBytes, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_3(int, _vsnprintf_s, _Post_z_ char, _Dest, _In_ size_t, _MaxCount, _In_z_ _Printf_format_string_ const char *, _Format, va_list, _Args)
#pragma warning(push)
#pragma warning(disable:4793)
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_ARGLIST_EX(int, __RETURN_POLICY_SAME, _CRTIMP, _snprintf, _vsnprintf, _Pre_notnull_ _Post_maybez_ char, _Out_writes_(_Count) _Post_maybez_, char, _Dest, _In_ size_t, _Count, _In_z_ _Printf_format_string_ const char *, _Format)
#pragma warning(pop)
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE int __cdecl vsprintf_s(_Out_writes_z_(_SizeInBytes) char * _DstBuf, _In_ size_t _SizeInBytes, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(int, vsprintf_s, _Post_z_ char, _Dest, _In_z_ _Printf_format_string_ const char *, _Format, va_list, _Args)
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl vsscanf_s(const char * _Src, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(int, vsscanf_s, _Post_z_ const char, _Src, _In_z_ _Printf_format_string_ const char *, _Format, va_list, _Args)
#endif /* __STDC_WANT_SECURE_LIB__ */
#pragma warning(push)
#pragma warning(disable:4793)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_ARGLIST(int, __RETURN_POLICY_SAME, _CRTIMP, sprintf, vsprintf, _Pre_notnull_ _Post_z_, char, _Dest, _In_z_ _Printf_format_string_ const char *, _Format)
_Check_return_opt_ _CRTIMP int __cdecl vsscanf(const char * _srcBuf, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
#pragma warning(pop)
_Check_return_ _CRTIMP int __cdecl _vscprintf(_In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _snprintf_c(_Out_writes_(_MaxCount) char * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vsnprintf_c(_Out_writes_(_MaxCount) char *_DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _fprintf_p(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl _printf_p(_In_z_ _Printf_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl _sprintf_p(_Out_writes_z_(_MaxCount) char * _Dst, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const char * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vfprintf_p(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vprintf_p(_In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vsprintf_p(_Out_writes_z_(_MaxCount) char * _Dst, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_Check_return_ _CRTIMP int __cdecl _scprintf_p(_In_z_ _Printf_format_string_ const char * _Format, ...);
_Check_return_ _CRTIMP int __cdecl _vscprintf_p(_In_z_ _Printf_format_string_ const char * _Format, va_list _ArgList);
_CRTIMP int __cdecl _set_printf_count_output(_In_ int _Value);
_CRTIMP int __cdecl _get_printf_count_output(void);
_Check_return_opt_ _CRTIMP int __cdecl _printf_l(_In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _printf_p_l(_In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _printf_s_l(_In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vprintf_l(_In_z_ _Printf_format_string_params_(2) const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vprintf_p_l(_In_z_ _Printf_format_string_params_(2) const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vprintf_s_l(_In_z_ _Printf_format_string_params_(2) const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _fprintf_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _fprintf_p_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _fprintf_s_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vfprintf_l(_Inout_ FILE * _File, _In_z_ const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vfprintf_p_l(_Inout_ FILE * _File, _In_z_ const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vfprintf_s_l(_Inout_ FILE * _File, _In_z_ const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_sprintf_s_l) _CRTIMP int __cdecl _sprintf_l(_Pre_notnull_ _Post_z_ char * _DstBuf, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _sprintf_p_l(_Out_writes_z_(_MaxCount) char * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _sprintf_s_l(_Out_writes_z_(_DstSize) char * _DstBuf, _In_ size_t _DstSize, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_vsprintf_s_l) _CRTIMP int __cdecl _vsprintf_l(_Pre_notnull_ _Post_z_ char * _DstBuf, _In_z_ const char * _Format, _In_opt_ _locale_t, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vsprintf_p_l(_Out_writes_z_(_MaxCount) char * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(2) const char* _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _vsprintf_s_l(_Out_writes_z_(_DstSize) char * _DstBuf, _In_ size_t _DstSize, _In_z_ _Printf_format_string_params_(2) const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _scprintf_l(_In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _scprintf_p_l(_In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vscprintf_l(_In_z_ _Printf_format_string_params_(2) const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vscprintf_p_l(_In_z_ _Printf_format_string_params_(2) const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_snprintf_s_l) _CRTIMP int __cdecl _snprintf_l(_Out_writes_(_MaxCount) char * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _snprintf_c_l(_Out_writes_(_MaxCount) char * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _snprintf_s_l(_Out_writes_z_(_DstSize) char * _DstBuf, _In_ size_t _DstSize, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(0) const char * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_vsnprintf_s_l) _CRTIMP int __cdecl _vsnprintf_l(_Out_writes_(_MaxCount) char * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(2) const char * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vsnprintf_c_l(_Out_writes_(_MaxCount) char * _DstBuf, _In_ size_t _MaxCount, const char *, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vsnprintf_s_l(_Out_writes_z_(_DstSize) char * _DstBuf, _In_ size_t _DstSize, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(2) const char* _Format,_In_opt_ _locale_t _Locale, va_list _ArgList);
#ifndef _WSTDIO_DEFINED
/* wide function prototypes, also declared in wchar.h */
#ifndef WEOF
#define WEOF (wint_t)(0xFFFF)
#endif /* WEOF */
_Check_return_ _CRTIMP FILE * __cdecl _wfsopen(_In_z_ const wchar_t * _Filename, _In_z_ const wchar_t * _Mode, _In_ int _ShFlag);
_Check_return_opt_ _CRTIMP wint_t __cdecl fgetwc(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP wint_t __cdecl _fgetwchar(void);
_Check_return_opt_ _CRTIMP wint_t __cdecl fputwc(_In_ wchar_t _Ch, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP wint_t __cdecl _fputwchar(_In_ wchar_t _Ch);
_Check_return_ _CRTIMP wint_t __cdecl getwc(_Inout_ FILE * _File);
_Check_return_ _CRTIMP wint_t __cdecl getwchar(void);
_Check_return_opt_ _CRTIMP wint_t __cdecl putwc(_In_ wchar_t _Ch, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP wint_t __cdecl putwchar(_In_ wchar_t _Ch);
_Check_return_opt_ _CRTIMP wint_t __cdecl ungetwc(_In_ wint_t _Ch, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP wchar_t * __cdecl fgetws(_Out_writes_z_(_SizeInWords) wchar_t * _Dst, _In_ int _SizeInWords, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl fputws(_In_z_ const wchar_t * _Str, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP wchar_t * __cdecl _getws_s(_Out_writes_z_(_SizeInWords) wchar_t * _Str, _In_ size_t _SizeInWords);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(wchar_t *, _getws_s, _Post_z_ wchar_t, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(wchar_t *, __RETURN_POLICY_SAME, _CRTIMP, _getws, _Pre_notnull_ _Post_z_, wchar_t, _String)
_Check_return_opt_ _CRTIMP int __cdecl _putws(_In_z_ const wchar_t * _Str);
_Check_return_opt_ _CRTIMP int __cdecl fwprintf(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl fwprintf_s(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl wprintf(_In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl wprintf_s(_In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_ _CRTIMP int __cdecl _scwprintf(_In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl vfwprintf(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl vfwscanf(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl vfwprintf_s(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl vfwscanf_s(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl vwprintf(_In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl vwscanf(_In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl vwprintf_s(_In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl vwscanf_s(_In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
#endif /* __STDC_WANT_SECURE_LIB__ */
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE int __cdecl swprintf_s(_Out_writes_z_(_SizeInWords) wchar_t * _Dst, _In_ size_t _SizeInWords, _In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1_ARGLIST(int, swprintf_s, vswprintf_s, _Post_z_ wchar_t, _Dest, _In_z_ _Printf_format_string_ const wchar_t *, _Format)
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE int __cdecl vswprintf_s(_Out_writes_z_(_SizeInWords) wchar_t * _Dst, _In_ size_t _SizeInWords, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl vswscanf_s(const wchar_t * _Src, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
#endif /* __STDC_WANT_SECURE_LIB__ */
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(int, vswprintf_s, _Post_z_ wchar_t, _Dest, _In_z_ _Printf_format_string_ const wchar_t *, _Format, va_list, _Args)
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(int, vswscanf_s, _Post_z_ wchar_t, _Dest, _In_z_ _Printf_format_string_ const wchar_t *, _Format, va_list, _Args)
_Check_return_opt_ _CRTIMP int __cdecl vswscanf(const wchar_t * _srcBuf, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _swprintf_c(_Out_writes_z_(_SizeInWords) wchar_t * _DstBuf, _In_ size_t _SizeInWords, _In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vswprintf_c(_Out_writes_z_(_SizeInWords) wchar_t * _DstBuf, _In_ size_t _SizeInWords, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _snwprintf_s(_Out_writes_z_(_SizeInWords) wchar_t * _DstBuf, _In_ size_t _SizeInWords, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2_ARGLIST(int, _snwprintf_s, _vsnwprintf_s, _Post_z_ wchar_t, _Dest, _In_ size_t, _Count, _In_z_ _Printf_format_string_ const wchar_t *, _Format)
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _vsnwprintf_s(_Out_writes_z_(_SizeInWords) wchar_t * _DstBuf, _In_ size_t _SizeInWords, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_3(int, _vsnwprintf_s, _Post_z_ wchar_t, _Dest, _In_ size_t, _Count, _In_z_ _Printf_format_string_ const wchar_t *, _Format, va_list, _Args)
#pragma warning(push)
#pragma warning(disable:4793)
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_ARGLIST_EX(int, __RETURN_POLICY_SAME, _CRTIMP, _snwprintf, _vsnwprintf, _Pre_notnull_ _Post_maybez_ wchar_t, _Out_writes_(_Count) _Post_maybez_, wchar_t, _Dest, _In_ size_t, _Count, _In_z_ _Printf_format_string_ const wchar_t *, _Format)
#pragma warning(pop)
_Check_return_opt_ _CRTIMP int __cdecl _fwprintf_p(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl _wprintf_p(_In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vfwprintf_p(_Inout_ FILE * _File, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vwprintf_p(_In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _swprintf_p(_Out_writes_z_(_MaxCount) wchar_t * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vswprintf_p(_Out_writes_z_(_MaxCount) wchar_t * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_ _CRTIMP int __cdecl _scwprintf_p(_In_z_ _Printf_format_string_ const wchar_t * _Format, ...);
_Check_return_ _CRTIMP int __cdecl _vscwprintf_p(_In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _wprintf_l(_In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _wprintf_p_l(_In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _wprintf_s_l(_In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vwprintf_l(_In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vwprintf_p_l(_In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vwprintf_s_l(_In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _fwprintf_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _fwprintf_p_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _fwprintf_s_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vfwprintf_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vfwprintf_p_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vfwprintf_s_l(_Inout_ FILE * _File, _In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _swprintf_c_l(_Out_writes_z_(_MaxCount) wchar_t * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _swprintf_p_l(_Out_writes_z_(_MaxCount) wchar_t * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _swprintf_s_l(_Out_writes_z_(_DstSize) wchar_t * _DstBuf, _In_ size_t _DstSize, _In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP int __cdecl _vswprintf_c_l(_Out_writes_z_(_MaxCount) wchar_t * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP int __cdecl _vswprintf_p_l(_Out_writes_z_(_MaxCount) wchar_t * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _vswprintf_s_l(_Out_writes_z_(_DstSize) wchar_t * _DstBuf, _In_ size_t _DstSize, _In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_ _CRTIMP int __cdecl _scwprintf_l(_In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_ _CRTIMP int __cdecl _scwprintf_p_l(_In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_ _CRTIMP int __cdecl _vscwprintf_p_l(_In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_snwprintf_s_l) _CRTIMP int __cdecl _snwprintf_l(_Out_writes_(_MaxCount) wchar_t * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _snwprintf_s_l(_Out_writes_z_(_DstSize) wchar_t * _DstBuf, _In_ size_t _DstSize, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_vsnwprintf_s_l) _CRTIMP int __cdecl _vsnwprintf_l(_Out_writes_(_MaxCount) wchar_t * _DstBuf, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _vsnwprintf_s_l(_Out_writes_z_(_DstSize) wchar_t * _DstBuf, _In_ size_t _DstSize, _In_ size_t _MaxCount, _In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
#ifndef _CRT_NON_CONFORMING_SWPRINTFS
#define _SWPRINTFS_DEPRECATED _CRT_DEPRECATE_TEXT("swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter. To use traditional Microsoft swprintf, set _CRT_NON_CONFORMING_SWPRINTFS.")
#else /* _CRT_NON_CONFORMING_SWPRINTFS */
#define _SWPRINTFS_DEPRECATED
#endif /* _CRT_NON_CONFORMING_SWPRINTFS */
/* we could end up with a double deprecation, disable warnings 4141 and 4996 */
#pragma warning(push)
#pragma warning(disable:4141 4996 4793)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_ARGLIST_EX(int, __RETURN_POLICY_SAME, _SWPRINTFS_DEPRECATED _CRTIMP, _swprintf, _swprintf_s, _vswprintf, vswprintf_s, _Pre_notnull_ _Post_z_, wchar_t, _Dest, _In_z_ _Printf_format_string_ const wchar_t *, _Format)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_2_ARGLIST_EX(int, __RETURN_POLICY_SAME, _SWPRINTFS_DEPRECATED _CRTIMP, __swprintf_l, __vswprintf_l, _vswprintf_s_l, _Pre_notnull_ _Post_z_ wchar_t, _Pre_notnull_ _Post_z_, wchar_t, _Dest, _In_z_ _Printf_format_string_params_(2) const wchar_t *, _Format, _locale_t, _Plocinfo)
#pragma warning(pop)
#if !defined (RC_INVOKED) && !defined (__midl)
#include <swprintf.inl>
#endif /* !defined (RC_INVOKED) && !defined (__midl) */
#ifdef _CRT_NON_CONFORMING_SWPRINTFS
#ifndef __cplusplus
#define swprintf _swprintf
#define vswprintf _vswprintf
#define _swprintf_l __swprintf_l
#define _vswprintf_l __vswprintf_l
#endif /* __cplusplus */
#endif /* _CRT_NON_CONFORMING_SWPRINTFS */
#if defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC)
#pragma push_macro("_wtempnam")
#undef _wtempnam
#endif /* defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC) */
_Check_return_ _CRTIMP wchar_t * __cdecl _wtempnam(_In_opt_z_ const wchar_t * _Directory, _In_opt_z_ const wchar_t * _FilePrefix);
#if defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_wtempnam")
#endif /* defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC) */
_Check_return_ _CRTIMP int __cdecl _vscwprintf(_In_z_ _Printf_format_string_ const wchar_t * _Format, va_list _ArgList);
_Check_return_ _CRTIMP int __cdecl _vscwprintf_l(_In_z_ _Printf_format_string_params_(2) const wchar_t * _Format, _In_opt_ _locale_t _Locale, va_list _ArgList);
_Check_return_ _CRT_INSECURE_DEPRECATE(fwscanf_s) _CRTIMP int __cdecl fwscanf(_Inout_ FILE * _File, _In_z_ _Scanf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_fwscanf_s_l) _CRTIMP int __cdecl _fwscanf_l(_Inout_ FILE * _File, _In_z_ _Scanf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
#pragma warning(push)
#pragma warning(disable:6530)
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl fwscanf_s(_Inout_ FILE * _File, _In_z_ _Scanf_s_format_string_ const wchar_t * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP int __cdecl _fwscanf_s_l(_Inout_ FILE * _File, _In_z_ _Scanf_s_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_ _CRT_INSECURE_DEPRECATE(swscanf_s) _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t * _Src, _In_z_ _Scanf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_swscanf_s_l) _CRTIMP int __cdecl _swscanf_l(_In_z_ const wchar_t * _Src, _In_z_ _Scanf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl swscanf_s(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_s_format_string_ const wchar_t * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _swscanf_s_l(_In_z_ const wchar_t * _Src, _In_z_ _Scanf_s_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_snwscanf_s) _CRTIMP int __cdecl _snwscanf(_In_reads_(_MaxCount) _Pre_z_ const wchar_t * _Src, _In_ size_t _MaxCount, _In_z_ _Scanf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_snwscanf_s_l) _CRTIMP int __cdecl _snwscanf_l(_In_reads_(_MaxCount) _Pre_z_ const wchar_t * _Src, _In_ size_t _MaxCount, _In_z_ _Scanf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _snwscanf_s(_In_reads_(_MaxCount) _Pre_z_ const wchar_t * _Src, _In_ size_t _MaxCount, _In_z_ _Scanf_s_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _snwscanf_s_l(_In_reads_(_MaxCount) _Pre_z_ const wchar_t * _Src, _In_ size_t _MaxCount, _In_z_ _Scanf_s_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
_Check_return_ _CRT_INSECURE_DEPRECATE(wscanf_s) _CRTIMP int __cdecl wscanf(_In_z_ _Scanf_format_string_ const wchar_t * _Format, ...);
_Check_return_opt_ _CRT_INSECURE_DEPRECATE(_wscanf_s_l) _CRTIMP int __cdecl _wscanf_l(_In_z_ _Scanf_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl wscanf_s(_In_z_ _Scanf_s_format_string_ const wchar_t * _Format, ...);
#endif /* __STDC_WANT_SECURE_LIB__ */
_Check_return_opt_ _CRTIMP_ALTERNATIVE int __cdecl _wscanf_s_l(_In_z_ _Scanf_s_format_string_params_(0) const wchar_t * _Format, _In_opt_ _locale_t _Locale, ...);
#pragma warning(pop)
_Check_return_ _CRTIMP FILE * __cdecl _wfdopen(_In_ int _FileHandle , _In_z_ const wchar_t * _Mode);
_Check_return_ _CRT_INSECURE_DEPRECATE(_wfopen_s) _CRTIMP FILE * __cdecl _wfopen(_In_z_ const wchar_t * _Filename, _In_z_ const wchar_t * _Mode);
_Check_return_wat_ _CRTIMP errno_t __cdecl _wfopen_s(_Outptr_result_maybenull_ FILE ** _File, _In_z_ const wchar_t * _Filename, _In_z_ const wchar_t * _Mode);
_Check_return_ _CRT_INSECURE_DEPRECATE(_wfreopen_s) _CRTIMP FILE * __cdecl _wfreopen(_In_z_ const wchar_t * _Filename, _In_z_ const wchar_t * _Mode, _Inout_ FILE * _OldFile);
_Check_return_wat_ _CRTIMP errno_t __cdecl _wfreopen_s(_Outptr_result_maybenull_ FILE ** _File, _In_z_ const wchar_t * _Filename, _In_z_ const wchar_t * _Mode, _Inout_ FILE * _OldFile);
#ifndef _CRT_WPERROR_DEFINED
#define _CRT_WPERROR_DEFINED
_CRTIMP void __cdecl _wperror(_In_opt_z_ const wchar_t * _ErrMsg);
#endif /* _CRT_WPERROR_DEFINED */
#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
_Check_return_ _CRTIMP FILE * __cdecl _wpopen(_In_z_ const wchar_t *_Command, _In_z_ const wchar_t * _Mode);
#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP */
_CRTIMP int __cdecl _wremove(_In_z_ const wchar_t * _Filename);
_Check_return_wat_ _CRTIMP errno_t __cdecl _wtmpnam_s(_Out_writes_z_(_SizeInWords) wchar_t * _DstBuf, _In_ size_t _SizeInWords);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _wtmpnam_s, _Post_z_ wchar_t, _Buffer)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wtmpnam, _Pre_maybenull_ _Post_z_, wchar_t, _Buffer)
_Check_return_opt_ _CRTIMP wint_t __cdecl _fgetwc_nolock(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP wint_t __cdecl _fputwc_nolock(_In_ wchar_t _Ch, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP wint_t __cdecl _ungetwc_nolock(_In_ wint_t _Ch, _Inout_ FILE * _File);
#ifdef _CRTBLD
#define _CRT_GETPUTWCHAR_NOINLINE
#else /* _CRTBLD */
#undef _CRT_GETPUTWCHAR_NOINLINE
#endif /* _CRTBLD */
#if !defined (__cplusplus) || defined (_M_CEE_PURE) || defined (_CRT_GETPUTWCHAR_NOINLINE)
#define getwchar() fgetwc(stdin)
#define putwchar(_c) fputwc((_c),stdout)
#else /* !defined (__cplusplus) || defined (_M_CEE_PURE) || defined (_CRT_GETPUTWCHAR_NOINLINE) */
inline _Check_return_ wint_t __CRTDECL getwchar()
{return (fgetwc(stdin)); } /* stdin */
inline _Check_return_opt_ wint_t __CRTDECL putwchar(_In_ wchar_t _C)
{return (fputwc(_C, stdout)); } /* stdout */
#endif /* !defined (__cplusplus) || defined (_M_CEE_PURE) || defined (_CRT_GETPUTWCHAR_NOINLINE) */
#define getwc(_stm) fgetwc(_stm)
#define putwc(_c,_stm) fputwc(_c,_stm)
#define _putwc_nolock(_c,_stm) _fputwc_nolock(_c,_stm)
#define _getwc_nolock(_stm) _fgetwc_nolock(_stm)
#if defined (_CRT_DISABLE_PERFCRIT_LOCKS) && !defined (_DLL)
#define fgetwc(_stm) _getwc_nolock(_stm)
#define fputwc(_c,_stm) _putwc_nolock(_c,_stm)
#define ungetwc(_c,_stm) _ungetwc_nolock(_c,_stm)
#endif /* defined (_CRT_DISABLE_PERFCRIT_LOCKS) && !defined (_DLL) */
#define _WSTDIO_DEFINED
#endif /* _WSTDIO_DEFINED */
#define _STDIO_DEFINED
#endif /* _STDIO_DEFINED */
/* Macro definitions */
#if defined (_CRT_DISABLE_PERFCRIT_LOCKS) && !defined (_DLL)
#define feof(_stream) ((_stream)->_flag & _IOEOF)
#define ferror(_stream) ((_stream)->_flag & _IOERR)
#define _fileno(_stream) ((_stream)->_file)
#define fgetc(_stream) (--(_stream)->_cnt >= 0 \
? 0xff & *(_stream)->_ptr++ : _filbuf(_stream))
#define putc(_c,_stream) (--(_stream)->_cnt >= 0 \
? 0xff & (*(_stream)->_ptr++ = (char)(_c)) : _flsbuf((_c),(_stream)))
#define getc(_stream) fgetc(_stream)
#define getchar() getc(stdin)
#define putchar(_c) putc((_c),stdout)
#endif /* defined (_CRT_DISABLE_PERFCRIT_LOCKS) && !defined (_DLL) */
#define _fgetc_nolock(_stream) (--(_stream)->_cnt >= 0 ? 0xff & *(_stream)->_ptr++ : _filbuf(_stream))
#define _fputc_nolock(_c,_stream) (--(_stream)->_cnt >= 0 ? 0xff & (*(_stream)->_ptr++ = (char)(_c)) : _flsbuf((_c),(_stream)))
#define _getc_nolock(_stream) _fgetc_nolock(_stream)
#define _putc_nolock(_c, _stream) _fputc_nolock(_c, _stream)
#define _getchar_nolock() _getc_nolock(stdin)
#define _putchar_nolock(_c) _putc_nolock((_c),stdout)
#define _getwchar_nolock() _getwc_nolock(stdin)
#define _putwchar_nolock(_c) _putwc_nolock((_c),stdout)
_CRTIMP void __cdecl _lock_file(_Inout_ FILE * _File);
_CRTIMP void __cdecl _unlock_file(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _fclose_nolock(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _fflush_nolock(_Inout_opt_ FILE * _File);
_Check_return_opt_ _CRTIMP size_t __cdecl _fread_nolock(_Out_writes_bytes_(_ElementSize*_Count) void * _DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP size_t __cdecl _fread_nolock_s(_Out_writes_bytes_(_ElementSize*_Count) void * _DstBuf, _In_ size_t _DstSize, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _fseek_nolock(_Inout_ FILE * _File, _In_ long _Offset, _In_ int _Origin);
_Check_return_ _CRTIMP long __cdecl _ftell_nolock(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _fseeki64_nolock(_Inout_ FILE * _File, _In_ __int64 _Offset, _In_ int _Origin);
_Check_return_ _CRTIMP __int64 __cdecl _ftelli64_nolock(_Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP size_t __cdecl _fwrite_nolock(_In_reads_bytes_(_Size*_Count) const void * _DstBuf, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE * _File);
_Check_return_opt_ _CRTIMP int __cdecl _ungetc_nolock(_In_ int _Ch, _Inout_ FILE * _File);
#if defined (_CRT_DISABLE_PERFCRIT_LOCKS) && !defined (_DLL)
#define fclose(_stm) _fclose_nolock(_stm)
#define fflush(_stm) _fflush_nolock(_stm)
#define fread(_DstBuf, _ElementSize, _Count, _File) _fread_nolock(_DstBuf, _ElementSize, _Count, _File)
#define fread_s(_DstBuf, _DstSize, _ElementSize, _Count, _File) _fread_nolock_s(_DstBuf, _DstSize, _ElementSize, _Count, _File)
#define fseek(_stm,_offset,_origin) _fseek_nolock(_stm,_offset,_origin)
#define ftell(_stm) _ftell_nolock(_stm)
#define _fseeki64(_stm,_offset,_origin) _fseeki64_nolock(_stm,_offset,_origin)
#define _ftelli64(_stm) _ftelli64_nolock(_stm)
#define fwrite(_buf,_siz,_cnt,_stm) _fwrite_nolock(_buf,_siz,_cnt,_stm)
#define ungetc(_c,_stm) _ungetc_nolock(_c,_stm)
#endif /* defined (_CRT_DISABLE_PERFCRIT_LOCKS) && !defined (_DLL) */
#if !__STDC__
/* Non-ANSI names for compatibility */
#define P_tmpdir _P_tmpdir
#define SYS_OPEN _SYS_OPEN
#if defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC)
#pragma push_macro("tempnam")
#undef tempnam
#endif /* defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC) */
_CRT_NONSTDC_DEPRECATE(_tempnam) _CRTIMP char * __cdecl tempnam(_In_opt_z_ const char * _Directory, _In_opt_z_ const char * _FilePrefix);
#if defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC)
#pragma pop_macro("tempnam")
#endif /* defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC) */
_Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_fcloseall) _CRTIMP int __cdecl fcloseall(void);
_Check_return_ _CRT_NONSTDC_DEPRECATE(_fdopen) _CRTIMP FILE * __cdecl fdopen(_In_ int _FileHandle, _In_z_ const char * _Format);
_Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_fgetchar) _CRTIMP int __cdecl fgetchar(void);
_Check_return_ _CRT_NONSTDC_DEPRECATE(_fileno) _CRTIMP int __cdecl fileno(_In_ FILE * _File);
_Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_flushall) _CRTIMP int __cdecl flushall(void);
_Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_fputchar) _CRTIMP int __cdecl fputchar(_In_ int _Ch);
_Check_return_ _CRT_NONSTDC_DEPRECATE(_getw) _CRTIMP int __cdecl getw(_Inout_ FILE * _File);
_Check_return_opt_ _CRT_NONSTDC_DEPRECATE(_putw) _CRTIMP int __cdecl putw(_In_ int _Ch, _Inout_ FILE * _File);
_Check_return_ _CRT_NONSTDC_DEPRECATE(_rmtmp) _CRTIMP int __cdecl rmtmp(void);
#endif /* !__STDC__ */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#pragma pack(pop)
#endif /* _INC_STDIO */