Skip to content

Commit

Permalink
smc-fuzzer: add sp printing support
Browse files Browse the repository at this point in the history
  • Loading branch information
07151129 committed Jan 22, 2020
1 parent 15a74a7 commit 0812833
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Tools/smc-fuzzer/smc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ void printUInt(SMCVal_t val) {
printf("%llu ", value);
}

/* VirtualSMCSDK/kern_vsmcapi.hpp */
static uint32_t getSpIntegral(const char* name) {
uint32_t ret = 0;
if (name && strlen(name) >= 3)
ret = _strtoul(&name[2], strlen(name) - 3, 16);

return ret / 16;
}

template <typename T>
constexpr T getBit(T n) {
return static_cast<T>(1U) << n;
}

void printSp(SMCVal_t val) {
uint32_t integral = getSpIntegral(val.dataType);
if (integral == 0)
return;
uint16_t value = ((uint8_t)val.bytes[0] << 8u) | (uint8_t)val.bytes[1];

double ret = (value & 0x7FFF) / static_cast<double>(getBit<uint16_t>(15 - integral));
ret = (value & 0x8000) ? -ret : ret;
printf("%f ", ret);
}

void printBytesHex(SMCVal_t val) {
int i;

Expand All @@ -96,8 +121,10 @@ void printVal(SMCVal_t val) {
(strcmp(val.dataType, DATATYPE_SINT16) == 0) ||
(strcmp(val.dataType, DATATYPE_SINT32) == 0))
printSInt(val);
else if (strcmp(val.dataType, DATATYPE_FPE2) == 0)
else if (strcmp(val.dataType, DATATYPE_FPE2) == 0)
printFPE2(val);
else if (!strncmp(val.dataType, "sp", 2))
printSp(val);

printBytesHex(val);
} else {
Expand Down

0 comments on commit 0812833

Please sign in to comment.