1
0
Fork 0

DBG: fix various issues pointed out by Visual Studio code analysis

This commit is contained in:
Duncan Ogilvie 2019-06-18 01:38:20 +02:00
parent d62f7f431c
commit 728f0eaa8d
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
22 changed files with 71 additions and 93 deletions

View File

@ -40,16 +40,16 @@ typedef struct
struct BridgeCFNode
{
duint parentGraph; //function of which this node is a part
duint start; //start of the block
duint end; //end of the block (inclusive)
duint brtrue; //destination if condition is true
duint brfalse; //destination if condition is false
duint icount; //number of instructions in node
bool terminal; //node is a RET
bool split; //node is a split (brtrue points to the next node)
bool indirectcall; //node contains indirect calls (call reg, call [reg+X])
void* userdata; //user data
duint parentGraph = 0; //function of which this node is a part
duint start = 0; //start of the block
duint end = 0; //end of the block (inclusive)
duint brtrue = 0; //destination if condition is true
duint brfalse = 0; //destination if condition is false
duint icount = 0; //number of instructions in node
bool terminal = false; //node is a RET
bool split = false; //node is a split (brtrue points to the next node)
bool indirectcall = false; //node contains indirect calls (call reg, call [reg+X])
void* userdata = nullptr; //user data
std::vector<duint> exits; //exits (including brtrue and brfalse)
std::vector<BridgeCFInstruction> instrs; //block instructions
@ -61,7 +61,9 @@ struct BridgeCFNode
__debugbreak();
}
explicit BridgeCFNode(const BridgeCFNodeList* nodeList, bool freedata)
BridgeCFNode() = default;
BridgeCFNode(const BridgeCFNodeList* nodeList, bool freedata)
{
if(!nodeList)
__debugbreak();
@ -81,30 +83,10 @@ struct BridgeCFNode
__debugbreak();
}
explicit BridgeCFNode(duint parentGraph, duint start, duint end)
BridgeCFNode(duint parentGraph, duint start, duint end)
: parentGraph(parentGraph),
start(start),
end(end),
brtrue(0),
brfalse(0),
icount(0),
terminal(false),
indirectcall(false),
split(false),
userdata(nullptr)
{
}
explicit BridgeCFNode()
: parentGraph(0),
start(0),
end(0),
brtrue(0),
brfalse(0),
icount(0),
terminal(false),
split(false),
userdata(nullptr)
end(end)
{
}

View File

@ -13,7 +13,7 @@
TraceRecordManager TraceRecord;
TraceRecordManager::TraceRecordManager() : instructionCounter(0)
TraceRecordManager::TraceRecordManager()
{
ModuleNames.emplace_back("");
}

View File

@ -94,11 +94,11 @@ private:
std::unordered_map<duint, TraceRecordPage> TraceRecord;
std::vector<std::string> ModuleNames;
unsigned int getModuleIndex(const String & moduleName);
unsigned int instructionCounter;
unsigned int instructionCounter = 0;
bool rtEnabled;
bool rtPrevInstAvailable;
HANDLE rtFile;
bool rtEnabled = false;
bool rtPrevInstAvailable = false;
HANDLE rtFile = nullptr;
REGDUMPWORD rtOldContext;
bool rtOldContextChanged[(FIELD_OFFSET(REGDUMP, lastError) + sizeof(DWORD)) / sizeof(duint)];

View File

@ -78,6 +78,7 @@ downslib_error downslib_download(const char* url,
// Get HTTP content length
char buffer[2048];
memset(buffer, 0, sizeof(buffer));
DWORD dwLen = sizeof(buffer);
unsigned long long total_bytes = 0;
if(HttpQueryInfoA(hUrl, HTTP_QUERY_CONTENT_LENGTH, buffer, &dwLen, 0))

View File

@ -43,7 +43,7 @@ public:
String ToString() const
{
return StringUtils::sprintf("start: p\nend: p\nfunction: %p", start, end, parentGraph);
return StringUtils::sprintf("start: %p\nend: %p\nfunction: %p", start, end, parentGraph);
}
};

View File

@ -291,7 +291,7 @@ bool cbInstrZydis(int argc, char* argv[])
dprintf_untranslated("register: %s\n", cp.RegName(op.reg.value));
break;
case ZYDIS_OPERAND_TYPE_IMMEDIATE:
dprintf_untranslated("immediate: 0x%p\n", op.imm.value);
dprintf_untranslated("immediate: 0x%p\n", op.imm.value.u);
break;
case ZYDIS_OPERAND_TYPE_MEMORY:
{

View File

@ -114,14 +114,12 @@ duint decodesimpledata(const unsigned char* buffer, ENCODETYPE type)
struct DataInstruction
{
ENCODETYPE type;
ENCODETYPE type = enc_unknown;
String operand;
};
bool parsedatainstruction(const char* instruction, DataInstruction & di)
{
di.type = enc_unknown;
di.operand.clear();
String instStr = StringUtils::Trim(String(instruction));
size_t pos = instStr.find_first_of(" \t");
String opcode = instStr.substr(0, pos);

View File

@ -19,9 +19,9 @@ private:
struct Function
{
String name;
int argc;
int argc = 0;
CBEXPRESSIONFUNCTION cbFunction;
void* userdata;
void* userdata = nullptr;
std::vector<String> aliases;
};

View File

@ -457,7 +457,7 @@ namespace Exprfunc
duint exinfo(duint index)
{
if(index >= 16)
if(index >= EXCEPTION_MAXIMUM_PARAMETERS)
return 0;
return getLastExceptionInfo().ExceptionRecord.ExceptionInformation[index];
}

View File

@ -20,7 +20,7 @@ private:
{
String type;
CBFORMATFUNCTION cbFunction;
void* userdata;
void* userdata = nullptr;
std::vector<String> aliases;
};

View File

@ -64,9 +64,9 @@ struct MODEXPORT : SymbolInfoGui
struct MODIMPORT : SymbolInfoGui
{
size_t moduleIndex; //index in MODINFO.importModules
DWORD iatRva;
duint ordinal; //equal to -1 if imported by name
size_t moduleIndex = 0; //index in MODINFO.importModules
DWORD iatRva = 0;
duint ordinal = -1; //equal to -1 if imported by name
String name;
String undecoratedName;

View File

@ -3,12 +3,7 @@
// Allocate a message stack
MESSAGE_STACK* MsgAllocStack()
{
auto stack = new MESSAGE_STACK;
stack->WaitingCalls = 0;
stack->Destroy = false;
return stack;
return new MESSAGE_STACK();
}
// Free a message stack

View File

@ -20,8 +20,8 @@ class MESSAGE_STACK
public:
Concurrency::unbounded_buffer<MESSAGE> msgs;
int WaitingCalls; // Number of threads waiting
bool Destroy; // Destroy stack as soon as possible
int WaitingCalls = 0; // Number of threads waiting
bool Destroy = false; // Destroy stack as soon as possible
};
// Function definitions

View File

@ -19,8 +19,8 @@ public:
struct Query_t
{
std::function<bool(DiaSymbol_t &)> callback;
bool collectUndecoratedNames;
bool collectSize;
bool collectUndecoratedNames = false;
bool collectSize = false;
};
private:

View File

@ -58,17 +58,17 @@ struct DiaValidationData_t
struct DiaSymbol_t
{
DiaSymbolType type;
uint64_t virtualAddress;
uint64_t size;
uint32_t offset;
uint32_t disp;
uint32_t segment;
DiaReachableType reachable;
DiaReturnableType returnable;
DiaCallingConvention convention;
bool perfectSize;
bool publicSymbol;
DiaSymbolType type = DiaSymbolType::ANY;
uint64_t virtualAddress = 0;
uint64_t size = 0;
uint32_t offset = 0;
uint32_t disp = 0;
uint32_t segment = 0;
DiaReachableType reachable = DiaReachableType::UNKNOWN;
DiaReturnableType returnable = DiaReturnableType::UNKNOWN;
DiaCallingConvention convention = DiaCallingConvention::UNKNOWN;
bool perfectSize = false;
bool publicSymbol = false;
std::string name;
std::string undecoratedName;
};

View File

@ -398,7 +398,7 @@ void StringUtils::ReplaceAll(WString & s, const WString & from, const WString &
}
}
String StringUtils::vsprintf(const char* format, va_list args)
String StringUtils::vsprintf(_In_z_ _Printf_format_string_ const char* format, va_list args)
{
char sbuffer[64] = "";
if(_vsnprintf_s(sbuffer, _TRUNCATE, format, args) != -1)
@ -419,7 +419,7 @@ String StringUtils::vsprintf(const char* format, va_list args)
return String(buffer.data());
}
String StringUtils::sprintf(_Printf_format_string_ const char* format, ...)
String StringUtils::sprintf(_In_z_ _Printf_format_string_ const char* format, ...)
{
va_list args;
va_start(args, format);
@ -428,7 +428,7 @@ String StringUtils::sprintf(_Printf_format_string_ const char* format, ...)
return result;
}
WString StringUtils::vsprintf(const wchar_t* format, va_list args)
WString StringUtils::vsprintf(_In_z_ _Printf_format_string_ const wchar_t* format, va_list args)
{
wchar_t sbuffer[64] = L"";
if(_vsnwprintf_s(sbuffer, _TRUNCATE, format, args) != -1)
@ -449,7 +449,7 @@ WString StringUtils::vsprintf(const wchar_t* format, va_list args)
return WString(buffer.data());
}
WString StringUtils::sprintf(_Printf_format_string_ const wchar_t* format, ...)
WString StringUtils::sprintf(_In_z_ _Printf_format_string_ const wchar_t* format, ...)
{
va_list args;
va_start(args, format);

View File

@ -17,7 +17,7 @@
struct SYMBOLCBDATA
{
CBSYMBOLENUM cbSymbolEnum;
void* user;
void* user = nullptr;
std::vector<char> decoratedSymbol;
std::vector<char> undecoratedSymbol;
};

View File

@ -15,12 +15,12 @@ struct SymbolInfoGui
struct SymbolInfo : SymbolInfoGui
{
duint rva;
duint size;
int32 disp;
duint rva = 0;
duint size = 0;
int32 disp = 0;
String decoratedName;
String undecoratedName;
bool publicSymbol;
bool publicSymbol = false;
void convertToGuiSymbol(duint modbase, SYMBOLINFO* info) const override
{
@ -35,10 +35,10 @@ struct SymbolInfo : SymbolInfoGui
struct LineInfo
{
duint rva;
duint size;
duint disp;
int lineNumber;
duint rva = 0;
duint size = 0;
duint disp = 0;
int lineNumber = 0;
String sourceFile;
};

View File

@ -57,7 +57,9 @@ enum
X_UNDNAME_NO_PTR64 = 0x20000, //Does not include ptr64 in output.
};
#if _MSC_VER != 1800
#if _MSC_VER == 1800 || _MSC_VER == 1900 || (_MSC_VER >= 1910 && _MSC_VER <= 1921)
// Tested compiler version
#else
#error unDNameEx is undocumented and possibly unsupported on your runtime! Uncomment this line if you understand the risks and want continue regardless...
#endif //_MSC_VER

View File

@ -65,8 +65,8 @@ namespace Types
std::string owner; //Function owner
std::string name; //Function identifier
std::string rettype; //Function return type
CallingConvention callconv; //Function calling convention
bool noreturn; //Function does not return (ExitProcess, _exit)
CallingConvention callconv = Cdecl; //Function calling convention
bool noreturn = false; //Function does not return (ExitProcess, _exit)
std::vector<Member> args; //Function arguments
};
@ -87,7 +87,7 @@ namespace Types
std::string kind;
std::string name;
std::string owner;
int size;
int size = 0;
};
explicit TypeManager();

View File

@ -23,18 +23,18 @@ struct VAR_VALUE
{
union
{
duint value;
duint value = 0;
std::vector<unsigned char>* data;
} u;
VAR_VALUE_TYPE type;
int size;
VAR_VALUE_TYPE type = VAR_UINT;
int size = 0;
};
struct VAR
{
String name;
String alias;
VAR_TYPE type;
VAR_TYPE type = VAR_SYSTEM;
VAR_VALUE value;
};

View File

@ -3,7 +3,7 @@
struct XREFSINFO : AddrInfo
{
XREFTYPE type;
XREFTYPE type = XREF_NONE;
std::unordered_map<duint, XREF_RECORD> references;
};