repo_name
string | dataset
string | owner
string | lang
string | func_name
string | code
string | docstring
string | url
string | sha
string |
---|---|---|---|---|---|---|---|---|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
js___date_now
|
static JSValue js___date_now(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
int64_t d;
struct timeval tv;
gettimeofday(&tv, NULL);
d = (int64_t)tv.tv_sec * 1000 + (tv.tv_usec / 1000);
return JS_NewInt64(ctx, d);
}
|
/* OS dependent: return the UTC time in ms since 1970. */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L42439-L42447
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
js___date_create
|
static JSValue js___date_create(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{
JSValue obj, proto;
proto = js_get_prototype_from_ctor(ctx, argv[0], argv[1]);
if (JS_IsException(proto))
return proto;
obj = JS_NewObjectProtoClass(ctx, proto, JS_CLASS_DATE);
JS_FreeValue(ctx, proto);
if (!JS_IsException(obj))
JS_SetObjectData(ctx, obj, JS_DupValue(ctx, argv[2]));
return obj;
}
|
/* create a new date object */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L42538-L42550
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
js_operator_set_finalizer
|
static void js_operator_set_finalizer(JSRuntime *rt, JSValue val)
{
JSOperatorSetData *opset = JS_GetOpaque(val, JS_CLASS_OPERATOR_SET);
int i, j;
JSBinaryOperatorDefEntry *ent;
if (opset) {
for(i = 0; i < JS_OVOP_COUNT; i++) {
if (opset->self_ops[i])
JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, opset->self_ops[i]));
}
for(j = 0; j < opset->left.count; j++) {
ent = &opset->left.tab[j];
for(i = 0; i < JS_OVOP_BINARY_COUNT; i++) {
if (ent->ops[i])
JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, ent->ops[i]));
}
}
js_free_rt(rt, opset->left.tab);
for(j = 0; j < opset->right.count; j++) {
ent = &opset->right.tab[j];
for(i = 0; i < JS_OVOP_BINARY_COUNT; i++) {
if (ent->ops[i])
JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, ent->ops[i]));
}
}
js_free_rt(rt, opset->right.tab);
js_free_rt(rt, opset);
}
}
|
/* Operators */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L49283-L49312
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
js_operators_create_internal
|
static JSValue js_operators_create_internal(JSContext *ctx,
int argc, JSValueConst *argv,
BOOL is_primitive)
{
JSValue opset_obj, prop, obj;
JSOperatorSetData *opset, *opset1;
JSBinaryOperatorDef *def;
JSValueConst arg;
int i, j;
JSBinaryOperatorDefEntry *new_tab;
JSBinaryOperatorDefEntry *ent;
uint32_t op_count;
if (ctx->rt->operator_count == UINT32_MAX) {
return JS_ThrowTypeError(ctx, "too many operators");
}
opset_obj = JS_NewObjectProtoClass(ctx, JS_NULL, JS_CLASS_OPERATOR_SET);
if (JS_IsException(opset_obj))
goto fail;
opset = js_mallocz(ctx, sizeof(*opset));
if (!opset)
goto fail;
JS_SetOpaque(opset_obj, opset);
if (argc >= 1) {
arg = argv[0];
/* self operators */
for(i = 0; i < JS_OVOP_COUNT; i++) {
prop = JS_GetPropertyStr(ctx, arg, js_overloadable_operator_names[i]);
if (JS_IsException(prop))
goto fail;
if (!JS_IsUndefined(prop)) {
if (check_function(ctx, prop)) {
JS_FreeValue(ctx, prop);
goto fail;
}
opset->self_ops[i] = JS_VALUE_GET_OBJ(prop);
}
}
}
/* left & right operators */
for(j = 1; j < argc; j++) {
arg = argv[j];
prop = JS_GetPropertyStr(ctx, arg, "left");
if (JS_IsException(prop))
goto fail;
def = &opset->right;
if (JS_IsUndefined(prop)) {
prop = JS_GetPropertyStr(ctx, arg, "right");
if (JS_IsException(prop))
goto fail;
if (JS_IsUndefined(prop)) {
JS_ThrowTypeError(ctx, "left or right property must be present");
goto fail;
}
def = &opset->left;
}
/* get the operator set */
obj = JS_GetProperty(ctx, prop, JS_ATOM_prototype);
JS_FreeValue(ctx, prop);
if (JS_IsException(obj))
goto fail;
prop = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_operatorSet);
JS_FreeValue(ctx, obj);
if (JS_IsException(prop))
goto fail;
opset1 = JS_GetOpaque2(ctx, prop, JS_CLASS_OPERATOR_SET);
if (!opset1) {
JS_FreeValue(ctx, prop);
goto fail;
}
op_count = opset1->operator_counter;
JS_FreeValue(ctx, prop);
/* we assume there are few entries */
new_tab = js_realloc(ctx, def->tab,
(def->count + 1) * sizeof(def->tab[0]));
if (!new_tab)
goto fail;
def->tab = new_tab;
def->count++;
ent = def->tab + def->count - 1;
memset(ent, 0, sizeof(def->tab[0]));
ent->operator_index = op_count;
for(i = 0; i < JS_OVOP_BINARY_COUNT; i++) {
prop = JS_GetPropertyStr(ctx, arg,
js_overloadable_operator_names[i]);
if (JS_IsException(prop))
goto fail;
if (!JS_IsUndefined(prop)) {
if (check_function(ctx, prop)) {
JS_FreeValue(ctx, prop);
goto fail;
}
ent->ops[i] = JS_VALUE_GET_OBJ(prop);
}
}
}
opset->is_primitive = is_primitive;
opset->operator_counter = ctx->rt->operator_count++;
return opset_obj;
fail:
JS_FreeValue(ctx, opset_obj);
return JS_EXCEPTION;
}
|
/* create an OperatorSet object */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L49348-L49452
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
JS_AddIntrinsicOperators
|
void JS_AddIntrinsicOperators(JSContext *ctx)
{
JSValue obj;
ctx->allow_operator_overloading = TRUE;
obj = JS_NewCFunction(ctx, js_global_operators, "Operators", 1);
JS_SetPropertyFunctionList(ctx, obj,
js_operators_funcs,
countof(js_operators_funcs));
JS_DefinePropertyValue(ctx, ctx->global_obj, JS_ATOM_Operators,
obj,
JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);
/* add default operatorSets */
js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_BOOLEAN]);
js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_NUMBER]);
js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_STRING]);
js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_BIG_INT]);
js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_BIG_FLOAT]);
js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_BIG_DECIMAL]);
}
|
/* must be called after all overloadable base types are initialized */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L49558-L49577
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
JS_ToBigIntCtorFree
|
static JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val)
{
uint32_t tag;
redo:
tag = JS_VALUE_GET_NORM_TAG(val);
switch(tag) {
case JS_TAG_INT:
case JS_TAG_BOOL:
val = JS_NewBigInt64(ctx, JS_VALUE_GET_INT(val));
break;
case JS_TAG_BIG_INT:
break;
case JS_TAG_FLOAT64:
case JS_TAG_BIG_FLOAT:
{
bf_t *a, a_s;
a = JS_ToBigFloat(ctx, &a_s, val);
if (!bf_is_finite(a)) {
JS_FreeValue(ctx, val);
val = JS_ThrowRangeError(ctx, "cannot convert NaN or Infinity to bigint");
} else {
JSValue val1 = JS_NewBigInt(ctx);
bf_t *r;
int ret;
if (JS_IsException(val1)) {
JS_FreeValue(ctx, val);
return JS_EXCEPTION;
}
r = JS_GetBigInt(val1);
ret = bf_set(r, a);
ret |= bf_rint(r, BF_RNDZ);
JS_FreeValue(ctx, val);
if (ret & BF_ST_MEM_ERROR) {
JS_FreeValue(ctx, val1);
val = JS_ThrowOutOfMemory(ctx);
} else if (ret & BF_ST_INEXACT) {
JS_FreeValue(ctx, val1);
val = JS_ThrowRangeError(ctx, "cannot convert to bigint: not an integer");
} else {
val = JS_CompactBigInt(ctx, val1);
}
}
if (a == &a_s)
bf_delete(a);
}
break;
case JS_TAG_BIG_DECIMAL:
val = JS_ToStringFree(ctx, val);
if (JS_IsException(val))
break;
goto redo;
case JS_TAG_STRING:
val = JS_StringToBigIntErr(ctx, val);
break;
case JS_TAG_OBJECT:
val = JS_ToPrimitiveFree(ctx, val, HINT_NUMBER);
if (JS_IsException(val))
break;
goto redo;
case JS_TAG_NULL:
case JS_TAG_UNDEFINED:
default:
JS_FreeValue(ctx, val);
return JS_ThrowTypeError(ctx, "cannot convert to bigint");
}
return val;
}
|
/* BigInt */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L49581-L49649
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
js_thisBigFloatValue
|
static JSValue js_thisBigFloatValue(JSContext *ctx, JSValueConst this_val)
{
if (JS_IsBigFloat(this_val))
return JS_DupValue(ctx, this_val);
if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {
JSObject *p = JS_VALUE_GET_OBJ(this_val);
if (p->class_id == JS_CLASS_BIG_FLOAT) {
if (JS_IsBigFloat(p->u.object_data))
return JS_DupValue(ctx, p->u.object_data);
}
}
return JS_ThrowTypeError(ctx, "not a bigfloat");
}
|
/* BigFloat */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L49922-L49935
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
js_float_env_constructor
|
static JSValue js_float_env_constructor(JSContext *ctx,
JSValueConst new_target,
int argc, JSValueConst *argv)
{
JSValue obj;
JSFloatEnv *fe;
int64_t prec;
int flags, rndmode;
prec = ctx->fp_env.prec;
flags = ctx->fp_env.flags;
if (!JS_IsUndefined(argv[0])) {
if (JS_ToInt64Sat(ctx, &prec, argv[0]))
return JS_EXCEPTION;
if (prec < BF_PREC_MIN || prec > BF_PREC_MAX)
return JS_ThrowRangeError(ctx, "invalid precision");
flags = BF_RNDN; /* RNDN, max exponent size, no subnormal */
if (argc > 1 && !JS_IsUndefined(argv[1])) {
if (JS_ToInt32Sat(ctx, &rndmode, argv[1]))
return JS_EXCEPTION;
if (rndmode < BF_RNDN || rndmode > BF_RNDF)
return JS_ThrowRangeError(ctx, "invalid rounding mode");
flags = rndmode;
}
}
obj = JS_NewObjectClass(ctx, JS_CLASS_FLOAT_ENV);
if (JS_IsException(obj))
return JS_EXCEPTION;
fe = js_malloc(ctx, sizeof(*fe));
if (!fe)
return JS_EXCEPTION;
fe->prec = prec;
fe->flags = flags;
fe->status = 0;
JS_SetOpaque(obj, fe);
return obj;
}
|
/* FloatEnv */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L50584-L50621
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
JS_ToBigDecimalFree
|
static JSValue JS_ToBigDecimalFree(JSContext *ctx, JSValue val,
BOOL allow_null_or_undefined)
{
redo:
switch(JS_VALUE_GET_NORM_TAG(val)) {
case JS_TAG_BIG_DECIMAL:
break;
case JS_TAG_NULL:
if (!allow_null_or_undefined)
goto fail;
/* fall thru */
case JS_TAG_BOOL:
case JS_TAG_INT:
{
bfdec_t *r;
int32_t v = JS_VALUE_GET_INT(val);
val = JS_NewBigDecimal(ctx);
if (JS_IsException(val))
break;
r = JS_GetBigDecimal(val);
if (bfdec_set_si(r, v)) {
JS_FreeValue(ctx, val);
val = JS_EXCEPTION;
break;
}
}
break;
case JS_TAG_FLOAT64:
case JS_TAG_BIG_INT:
case JS_TAG_BIG_FLOAT:
val = JS_ToStringFree(ctx, val);
if (JS_IsException(val))
break;
goto redo;
case JS_TAG_STRING:
{
const char *str, *p;
size_t len;
int err;
str = JS_ToCStringLen(ctx, &len, val);
JS_FreeValue(ctx, val);
if (!str)
return JS_EXCEPTION;
p = str;
p += skip_spaces(p);
if ((p - str) == len) {
bfdec_t *r;
val = JS_NewBigDecimal(ctx);
if (JS_IsException(val))
break;
r = JS_GetBigDecimal(val);
bfdec_set_zero(r, 0);
err = 0;
} else {
val = js_atof(ctx, p, &p, 0, ATOD_TYPE_BIG_DECIMAL);
if (JS_IsException(val)) {
JS_FreeCString(ctx, str);
return JS_EXCEPTION;
}
p += skip_spaces(p);
err = ((p - str) != len);
}
JS_FreeCString(ctx, str);
if (err) {
JS_FreeValue(ctx, val);
return JS_ThrowSyntaxError(ctx, "invalid bigdecimal literal");
}
}
break;
case JS_TAG_OBJECT:
val = JS_ToPrimitiveFree(ctx, val, HINT_NUMBER);
if (JS_IsException(val))
break;
goto redo;
case JS_TAG_UNDEFINED:
{
bfdec_t *r;
if (!allow_null_or_undefined)
goto fail;
val = JS_NewBigDecimal(ctx);
if (JS_IsException(val))
break;
r = JS_GetBigDecimal(val);
bfdec_set_nan(r);
}
break;
default:
fail:
JS_FreeValue(ctx, val);
return JS_ThrowTypeError(ctx, "cannot convert to bigdecimal");
}
return val;
}
|
/* BigDecimal */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L50831-L50925
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
js_typed_array___getLength
|
static JSValue js_typed_array___getLength(JSContext *ctx,
JSValueConst this_val,
int argc, JSValueConst *argv)
{
BOOL ignore_detached = JS_ToBool(ctx, argv[1]);
if (ignore_detached) {
return js_typed_array_get_length(ctx, argv[0]);
} else {
int len;
len = js_typed_array_get_length_internal(ctx, argv[0]);
if (len < 0)
return JS_EXCEPTION;
return JS_NewInt32(ctx, len);
}
}
|
/* validate a typed array and return its length */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L52203-L52218
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
JS_GetObjectClassName
|
JSValue JS_GetObjectClassName(JSContext *ctx, JSValueConst obj)
{
JSValue ctor = JS_GetProperty(ctx, obj, JS_ATOM_constructor);
JSObject *p;
if (JS_VALUE_GET_TAG(ctor) != JS_TAG_OBJECT)
goto fail;
p = JS_VALUE_GET_OBJ(ctor);
if (p->class_id != JS_CLASS_BYTECODE_FUNCTION)
goto fail;
JSValue name = JS_GetProperty(ctx, ctor, JS_ATOM_name);
JS_FreeValue(ctx, ctor);
return name;
fail:
JS_FreeValue(ctx, ctor);
return JS_UNDEFINED;
}
|
/* get name of user's class. For this obj:
class Account {}
var obj = new Account();
it will return "Account" */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L54719-L54737
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
JS_GetLocalValue
|
JSValue JS_GetLocalValue(JSContext *ctx, JSAtom name)
{
for (JSStackFrame *sf = ctx->rt->current_stack_frame; sf != NULL; sf = sf->prev_frame) {
JSObject *f = JS_VALUE_GET_OBJ(sf->cur_func);
if (!f || !js_class_has_bytecode(f->class_id))
break;
JSFunctionBytecode *b = f->u.func.function_bytecode;
for (uint32_t i = 0; i < b->arg_count + b->var_count; i++) {
JSValue var_val;
if (i < b->arg_count)
var_val = sf->arg_buf[i];
else
var_val = sf->var_buf[i - b->arg_count];
if (JS_IsUninitialized(var_val))
continue;
JSVarDef *vd = b->vardefs + i;
if(name == vd->var_name)
return JS_DupValue(ctx, var_val);
}
}
return JS_UNDEFINED;
}
|
/* get value defined in local call frames/namespaces */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/BugChecker/QuickJS/quickjs.c#L54741-L54767
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
RestrictTest
|
static size_t RestrictTest(char* EA_RESTRICT p)
{
return sizeof(p);
}
|
// Should fail.
//static_assert(sizeof(int32_t) == 8, "static_assert failure");
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/EABase/test/source/TestEABaseC.c#L228-L231
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
EAMain
|
int EAMain(int argc, char** argv)
{
int nErrorCount = 0, nTotalErrorCount = 0;
(void)argc;
(void)argv;
nErrorCount = TestEABase();
Printf("EABase test error count: %d\n\n", nErrorCount);
nTotalErrorCount += nErrorCount;
nErrorCount = TestEAPlatform();
Printf("EAPlatform test error count: %d\n\n", nErrorCount);
nTotalErrorCount += nErrorCount;
nErrorCount = TestEACompiler();
Printf("EACompiler test error count: %d\n\n", nErrorCount);
nTotalErrorCount += nErrorCount;
nErrorCount = TestEACompilerTraits();
Printf("EACompilerTraits test error count: %d\n\n", nErrorCount);
nTotalErrorCount += nErrorCount;
if (nTotalErrorCount == 0)
Printf("\nAll tests completed successfully.\n");
else
Printf("\nTests failed. Total error count: %d\n", nTotalErrorCount);
return nTotalErrorCount;
}
|
// The test below should cause compilation to fail if it is uncommented. However we can't
// obviously enable the test because it will break the build. It should be tested manually
// if changes to EA_IS_ENABLED are made.
//
// #if EA_IS_ENABLED(EABASE_TEST_FEATURE_WITH_NO_DEFINE)
// #endif
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/EABase/test/source/TestEABaseC.c#L1184-L1213
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
PerformBasicTests
|
static ZyanStatus PerformBasicTests(ZyanString* string)
{
ZYAN_ASSERT(string);
ZYAN_UNUSED(string);
return ZYAN_STATUS_SUCCESS;
}
|
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/* ============================================================================================== */
/* Helper functions */
/* ============================================================================================== */
/* ============================================================================================== */
/* Tests */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Basic tests */
/* ---------------------------------------------------------------------------------------------- */
/**
* Performs some basic test on the given `ZyanString` instance.
*
* @param string A pointer to the `ZyanString` instance.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/String.c#L63-L71
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
TestDynamic
|
static ZyanStatus TestDynamic(void)
{
PerformBasicTests(ZYAN_NULL);
return ZYAN_STATUS_SUCCESS;
}
|
/**
* Performs basic tests on a string that dynamically manages memory.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/String.c#L78-L82
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
TestStatic
|
static ZyanStatus TestStatic(void)
{
PerformBasicTests(ZYAN_NULL);
return ZYAN_STATUS_SUCCESS;
}
|
/**
* Performs basic tests on a string that uses a static buffer.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/String.c#L89-L93
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
TestAllocator
|
static ZyanStatus TestAllocator(void)
{
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Custom allocator */
/* ---------------------------------------------------------------------------------------------- */
//static ZyanStatus AllocatorAllocate(ZyanAllocator* allocator, void** p, ZyanUSize element_size,
// ZyanUSize n)
//{
// ZYAN_ASSERT(allocator);
// ZYAN_ASSERT(p);
// ZYAN_ASSERT(element_size);
// ZYAN_ASSERT(n);
//
// ZYAN_UNUSED(allocator);
//
// *p = ZYAN_MALLOC(element_size * n);
// if (!*p)
// {
// return ZYAN_STATUS_NOT_ENOUGH_MEMORY;
// }
//
// return ZYAN_STATUS_SUCCESS;
//}
//
//static ZyanStatus AllocatorReallocate(ZyanAllocator* allocator, void** p, ZyanUSize element_size,
// ZyanUSize n)
//{
// ZYAN_ASSERT(allocator);
// ZYAN_ASSERT(p);
// ZYAN_ASSERT(element_size);
// ZYAN_ASSERT(n);
//
// ZYAN_UNUSED(allocator);
//
// void* const x = ZYAN_REALLOC(*p, element_size * n);
// if (!x)
// {
// return ZYAN_STATUS_NOT_ENOUGH_MEMORY;
// }
// *p = x;
//
// return ZYAN_STATUS_SUCCESS;
//}
//
//static ZyanStatus AllocatorDeallocate(ZyanAllocator* allocator, void* p, ZyanUSize element_size,
// ZyanUSize n)
//{
// ZYAN_ASSERT(allocator);
// ZYAN_ASSERT(p);
// ZYAN_ASSERT(element_size);
// ZYAN_ASSERT(n);
//
// ZYAN_UNUSED(allocator);
// ZYAN_UNUSED(element_size);
// ZYAN_UNUSED(n);
//
// ZYAN_FREE(p);
//
// return ZYAN_STATUS_SUCCESS;
//}
/* ---------------------------------------------------------------------------------------------- */
/**
* Performs basic tests on a vector that dynamically manages memory using a custom
* allocator and modified growth-factor/shrink-threshold.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/String.c#L163-L166
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
main
|
int main()
{
if (!ZYAN_SUCCESS(TestDynamic()))
{
return EXIT_FAILURE;
}
if (!ZYAN_SUCCESS(TestStatic()))
{
return EXIT_FAILURE;
}
if (!ZYAN_SUCCESS(TestAllocator()))
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/String.c#L174-L190
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
InitTestdata
|
static void InitTestdata(TestStruct* data, ZyanU32 n)
{
ZYAN_ASSERT(data);
data->u32 = n;
data->u64 = n;
data->f = (float)n;
}
|
/* ============================================================================================== */
/* Helper functions */
/* ============================================================================================== */
/**
* Initializes the given `TestStruct` struct.
*
* @param data A pointer to the `TestStruct` struct.
* @param n The number to initialize the struct with.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L65-L72
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
PerformBasicTests
|
static ZyanStatus PerformBasicTests(ZyanVector* vector)
{
ZYAN_ASSERT(vector);
static TestStruct e_v;
static const TestStruct* e_p;
// Insert `20` elements. The vector automatically manages its size
for (ZyanU32 i = 0; i < 20; ++i)
{
InitTestdata(&e_v, i);
ZYAN_CHECK(ZyanVectorPushBack(vector, &e_v));
}
// Remove elements `#05..#09`
ZYAN_CHECK(ZyanVectorDeleteRange(vector, 5, 5));
// Insert a new element at index `#05`
InitTestdata(&e_v, 12345678);
ZYAN_CHECK(ZyanVectorInsert(vector, 5, &e_v));
// Change value of element `#15`
InitTestdata(&e_v, 87654321);
ZYAN_CHECK(ZyanVectorSet(vector, 10, &e_v));
// Print `u64` of all vector elements
ZyanUSize value;
ZYAN_CHECK(ZyanVectorGetSize(vector, &value));
puts("ELEMENTS");
for (ZyanUSize i = 0; i < value; ++i)
{
ZYAN_CHECK(ZyanVectorGetPointer(vector, i, (const void**)&e_p));
printf(" Element #%02" PRIuPTR ": %08" PRIu64 "\n", i, e_p->u64);
}
// Print infos
puts("INFO");
printf(" Size : %08" PRIuPTR "\n", value);
ZYAN_CHECK(ZyanVectorGetCapacity(vector, &value));
printf(" Capacity : %08" PRIuPTR "\n\n", value);
return ZYAN_STATUS_SUCCESS;
}
|
/* ============================================================================================== */
/* Tests */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Basic tests */
/* ---------------------------------------------------------------------------------------------- */
/**
* Performs some basic test on the given `ZyanVector` instance.
*
* @param vector A pointer to the `ZyanVector` instance.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L89-L131
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
TestDataComparison
|
static ZyanI32 TestDataComparison(const TestStruct* left, const TestStruct* right)
{
ZYAN_ASSERT(left);
ZYAN_ASSERT(right);
if (left->u32 < right->u32)
{
return -1;
}
if (left->u32 > right->u32)
{
return 1;
}
return 0;
}
|
/**
* A dummy comparison function for the `TestStruct` that uses the `u32` field as key
* value.
*
* @param left A pointer to the first element.
* @param right A pointer to the second element.
*
* @return Returns values in the following range:
* `left == right -> result == 0`
* `left < right -> result < 0`
* `left > right -> result > 0`
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L145-L159
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
PerformBinarySearchTest
|
static ZyanStatus PerformBinarySearchTest(ZyanVector* vector)
{
ZYAN_ASSERT(vector);
static TestStruct e_v;
static const TestStruct* e_p;
ZyanUSize value;
ZYAN_CHECK(ZyanVectorGetCapacity(vector, &value));
// Create a sorted test vector
for (ZyanUSize i = 0; i < value; ++i)
{
const ZyanU32 n = rand() % 100;
InitTestdata(&e_v, n);
ZyanUSize found_index;
ZYAN_CHECK(ZyanVectorBinarySearch(vector, &e_v, &found_index,
(ZyanComparison)&TestDataComparison));
ZYAN_CHECK(ZyanVectorInsert(vector, found_index, &e_v));
}
// Print `u32` of all vector elements
ZYAN_CHECK(ZyanVectorGetSize(vector, &value));
puts("ELEMENTS");
for (ZyanUSize i = 0; i < value; ++i)
{
ZYAN_CHECK(ZyanVectorGetPointer(vector, i, (const void**)&e_p));
printf(" Element #%02" PRIuPTR ": %08" PRIu32 "\n", i, e_p->u32);
}
return ZYAN_STATUS_SUCCESS;
}
|
/**
* Tests the binary-search functionality of the given `ZyanVector` instance.
*
* @param vector A pointer to the `ZyanVector` instance.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L168-L200
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
TestDynamic
|
static ZyanStatus TestDynamic(void)
{
// Initialize vector with a base capacity of `10` elements
ZyanVector vector;
ZYAN_CHECK(ZyanVectorInit(&vector, sizeof(TestStruct), 10, ZYAN_NULL));
ZYAN_CHECK(PerformBasicTests(&vector));
ZYAN_CHECK(ZyanVectorClear(&vector));
ZYAN_CHECK(ZyanVectorReserve(&vector, 20));
ZYAN_CHECK(PerformBinarySearchTest(&vector));
// Cleanup
return ZyanVectorDestroy(&vector);
}
|
/**
* Performs basic tests on a vector that dynamically manages memory.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L207-L220
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
TestStatic
|
static ZyanStatus TestStatic(void)
{
static TestStruct buffer[20];
// Initialize vector to use a static buffer with a total capacity of `20` elements.
ZyanVector vector;
ZYAN_CHECK(ZyanVectorInitCustomBuffer(&vector, sizeof(TestStruct), buffer,
ZYAN_ARRAY_LENGTH(buffer), ZYAN_NULL));
// Compare elements
ZyanUSize size;
ZYAN_CHECK(ZyanVectorGetSize(&vector, &size));
for (ZyanUSize i = 0; i < size; ++i)
{
static TestStruct* element;
ZYAN_CHECK(ZyanVectorGetPointer(&vector, i, (const void**)&element));
if (element->u64 != buffer[i].u64)
{
return ZYAN_STATUS_INVALID_OPERATION;
}
}
ZYAN_CHECK(PerformBasicTests(&vector));
ZYAN_CHECK(ZyanVectorClear(&vector));
ZYAN_CHECK(PerformBinarySearchTest(&vector));
// Cleanup
return ZyanVectorDestroy(&vector);
}
|
/**
* Performs basic tests on a vector that uses a static buffer.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L227-L255
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
AllocatorAllocate
|
static ZyanStatus AllocatorAllocate(ZyanAllocator* allocator, void** p, ZyanUSize element_size,
ZyanUSize n)
{
ZYAN_ASSERT(allocator);
ZYAN_ASSERT(p);
ZYAN_ASSERT(element_size);
ZYAN_ASSERT(n);
ZYAN_UNUSED(allocator);
*p = ZYAN_MALLOC(element_size * n);
if (!*p)
{
return ZYAN_STATUS_NOT_ENOUGH_MEMORY;
}
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Custom allocator */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L261-L278
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
TestAllocator
|
static ZyanStatus TestAllocator(void)
{
ZyanAllocator allocator;
ZYAN_CHECK(ZyanAllocatorInit(&allocator, &AllocatorAllocate, &AllocatorReallocate,
&AllocatorDeallocate));
// Initialize vector with a base capacity of `10` elements. Growth-factor is set to 10 and
// dynamic shrinking is disabled
ZyanVector vector;
ZYAN_CHECK(ZyanVectorInitEx(&vector, sizeof(TestStruct), 5, ZYAN_NULL, &allocator,
10, 0));
static TestStruct e_v;
// Insert `10` elements. The vector automatically manages its size
for (ZyanU32 i = 0; i < 10; ++i)
{
InitTestdata(&e_v, i);
ZYAN_CHECK(ZyanVectorPushBack(&vector, &e_v));
}
// Check capacity
ZyanUSize value;
ZYAN_CHECK(ZyanVectorGetCapacity(&vector, &value));
if (value != 60) // (5 + 1) * 10.0f
{
return ZYAN_STATUS_INVALID_OPERATION;
}
// Remove all elements
ZYAN_CHECK(ZyanVectorClear(&vector));
// Print infos
puts("INFO");
ZYAN_CHECK(ZyanVectorGetSize(&vector, &value));
printf(" Size : %08" PRIuPTR "\n", value);
ZYAN_CHECK(ZyanVectorGetCapacity(&vector, &value));
printf(" Capacity : %08" PRIuPTR "\n\n", value);
// Cleanup
return ZyanVectorDestroy(&vector);
}
|
/* ---------------------------------------------------------------------------------------------- */
/**
* Performs basic tests on a vector that dynamically manages memory using a custom
* allocator and modified growth-factor/shrink-threshold.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L325-L366
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
main
|
int main()
{
time_t t;
srand((unsigned)time(&t));
if (!ZYAN_SUCCESS(TestDynamic()))
{
return EXIT_FAILURE;
}
if (!ZYAN_SUCCESS(TestStatic()))
{
return EXIT_FAILURE;
}
if (!ZYAN_SUCCESS(TestAllocator()))
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/examples/Vector.c#L374-L393
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanAllocatorInit
|
ZyanStatus ZyanAllocatorInit(ZyanAllocator* allocator, ZyanAllocatorAllocate allocate,
ZyanAllocatorAllocate reallocate, ZyanAllocatorDeallocate deallocate)
{
if (!allocator || !allocate || !reallocate || !deallocate)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
allocator->allocate = allocate;
allocator->reallocate = reallocate;
allocator->deallocate = deallocate;
return ZYAN_STATUS_SUCCESS;
}
|
// ZYAN_NO_LIBC
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Allocator.c#L104-L117
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetInitVectorElements
|
static ZyanStatus ZyanBitsetInitVectorElements(ZyanVector* vector, ZyanUSize count)
{
ZYAN_ASSERT(vector);
static const ZyanU8 zero = 0;
for (ZyanUSize i = 0; i < count; ++i)
{
ZYAN_CHECK(ZyanVectorPushBack(vector, &zero));
}
return ZYAN_STATUS_SUCCESS;
}
|
/* ============================================================================================== */
/* Internal functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Helper functions */
/* ---------------------------------------------------------------------------------------------- */
/**
* Initializes the given `vector` with `count` "zero"-bytes.
*
* @param vector A pointer to the `ZyanVector` instance.
* @param count The number of bytes.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L87-L98
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetOperationAND
|
static ZyanStatus ZyanBitsetOperationAND(ZyanU8* b1, const ZyanU8* b2)
{
*b1 &= *b2;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Byte operations */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L104-L108
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetInitEx
|
ZyanStatus ZyanBitsetInitEx(ZyanBitset* bitset, ZyanUSize count, ZyanAllocator* allocator,
ZyanU8 growth_factor, ZyanU8 shrink_threshold)
{
if (!bitset)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
const ZyanU32 bytes = ZYAN_BITSET_BITS_TO_BYTES(count);
bitset->size = count;
ZYAN_CHECK(ZyanVectorInitEx(&bitset->bits, sizeof(ZyanU8), bytes, ZYAN_NULL, allocator,
growth_factor, shrink_threshold));
ZYAN_CHECK(ZyanBitsetInitVectorElements(&bitset->bits, bytes));
return ZYAN_STATUS_SUCCESS;
}
|
// ZYAN_NO_LIBC
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L142-L158
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetPerformByteOperation
|
ZyanStatus ZyanBitsetPerformByteOperation(ZyanBitset* destination, const ZyanBitset* source,
ZyanBitsetByteOperation operation)
{
if (!destination || !source || !operation)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZyanUSize s1;
ZyanUSize s2;
ZYAN_CHECK(ZyanVectorGetSize(&destination->bits, &s1));
ZYAN_CHECK(ZyanVectorGetSize(&source->bits, &s2));
const ZyanUSize min = ZYAN_MIN(s1, s2);
for (ZyanUSize i = 0; i < min; ++i)
{
ZyanU8* v1;
const ZyanU8* v2;
ZYAN_CHECK(ZyanVectorGetPointerMutable(&destination->bits, i, (void**)&v1));
ZYAN_CHECK(ZyanVectorGetPointer(&source->bits, i, (const void**)&v2));
ZYAN_ASSERT(v1);
ZYAN_ASSERT(v2);
ZYAN_CHECK(operation(v1, v2));
}
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Logical operations */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L196-L224
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetSet
|
ZyanStatus ZyanBitsetSet(ZyanBitset* bitset, ZyanUSize index)
{
if (!bitset)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (index >= bitset->size)
{
return ZYAN_STATUS_OUT_OF_RANGE;
}
ZyanU8* value;
ZYAN_CHECK(ZyanVectorGetPointerMutable(&bitset->bits, index / 8, (void**)&value));
*value |= (1 << ZYAN_BITSET_BIT_OFFSET(index));
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Bit access */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L264-L281
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetSetAll
|
ZyanStatus ZyanBitsetSetAll(ZyanBitset* bitset)
{
if (!bitset)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZyanUSize size;
ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size));
for (ZyanUSize i = 0; i < size; ++i)
{
ZyanU8* value;
ZYAN_CHECK(ZyanVectorGetPointerMutable(&bitset->bits, i, (void**)&value));
*value = 0xFF;
}
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L365-L382
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetPush
|
ZyanStatus ZyanBitsetPush(ZyanBitset* bitset, ZyanBool value)
{
if (!bitset)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if ((bitset->size++ % 8) == 0)
{
static const ZyanU8 zero = 0;
ZYAN_CHECK(ZyanVectorPushBack(&bitset->bits, &zero));
}
return ZyanBitsetAssign(bitset, bitset->size - 1, value);
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Size management */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L407-L421
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetReserve
|
ZyanStatus ZyanBitsetReserve(ZyanBitset* bitset, ZyanUSize count)
{
return ZyanVectorReserve(&bitset->bits, ZYAN_BITSET_BITS_TO_BYTES(count));
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Memory management */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L453-L456
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetGetSize
|
ZyanStatus ZyanBitsetGetSize(const ZyanBitset* bitset, ZyanUSize* size)
{
if (!bitset)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
*size = bitset->size;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Information */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L467-L477
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanBitsetCount
|
ZyanStatus ZyanBitsetCount(const ZyanBitset* bitset, ZyanUSize* count)
{
if (!bitset || !count)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
*count = 0;
ZyanUSize size;
ZYAN_CHECK(ZyanVectorGetSize(&bitset->bits, &size));
for (ZyanUSize i = 0; i < size; ++i)
{
ZyanU8* value;
ZYAN_CHECK(ZyanVectorGetPointer(&bitset->bits, i, (const void**)&value));
ZyanU8 popcnt = *value;
popcnt = (popcnt & 0x55) + ((popcnt >> 1) & 0x55);
popcnt = (popcnt & 0x33) + ((popcnt >> 2) & 0x33);
popcnt = (popcnt & 0x0F) + ((popcnt >> 4) & 0x0F);
*count += popcnt;
}
*count = ZYAN_MIN(*count, bitset->size);
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Bitset.c#L509-L536
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringAppendDecU
|
ZyanStatus ZyanStringAppendDecU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length)
{
#if defined(ZYAN_X64) || defined(ZYAN_AARCH64)
return ZyanStringAppendDecU64(string, value, padding_length);
#else
// Working with 64-bit values is slow on non 64-bit systems
if (value & 0xFFFFFFFF00000000)
{
return ZyanStringAppendDecU64(string, value, padding_length);
}
return ZyanStringAppendDecU32(string, (ZyanU32)value, padding_length);
#endif
}
|
// ZYAN_NO_LIBC
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Format.c#L424-L436
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanListAllocateNode
|
static ZyanStatus ZyanListAllocateNode(ZyanList* list, ZyanListNode** node)
{
ZYAN_ASSERT(list);
ZYAN_ASSERT(node);
const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL);
if (is_dynamic)
{
ZYAN_ASSERT(list->allocator->allocate);
ZYAN_CHECK(list->allocator->allocate(list->allocator, (void**)node,
sizeof(ZyanListNode) + list->element_size, 1));
} else
{
if (list->first_unused)
{
*node = list->first_unused;
list->first_unused = (*node)->next;
} else
{
const ZyanUSize size = list->size * (sizeof(ZyanListNode) + list->element_size);
if (size + (sizeof(ZyanListNode) + list->element_size) > list->capacity)
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
*node = (ZyanListNode*)((ZyanU8*)list->buffer + size);
}
}
return ZYAN_STATUS_SUCCESS;
}
|
/* ============================================================================================== */
/* Internal functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Helper functions */
/* ---------------------------------------------------------------------------------------------- */
/**
* Allocates memory for a new list node.
*
* @param list A pointer to the `ZyanList` instance.
* @param node Receives a pointer to the new `ZyanListNode` struct.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/List.c#L60-L90
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanListDeallocateNode
|
static ZyanStatus ZyanListDeallocateNode(ZyanList* list, ZyanListNode* node)
{
ZYAN_ASSERT(list);
ZYAN_ASSERT(node);
const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL);
if (is_dynamic)
{
ZYAN_ASSERT(list->allocator->deallocate);
ZYAN_CHECK(list->allocator->deallocate(list->allocator, (void*)node,
sizeof(ZyanListNode) + list->element_size, 1));
} else
{
node->next = list->first_unused;
list->first_unused = node;
}
return ZYAN_STATUS_SUCCESS;
}
|
/**
* Frees memory of a node.
*
* @param list A pointer to the `ZyanList` instance.
* @param node A pointer to the `ZyanListNode` struct.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/List.c#L100-L118
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanListInitEx
|
ZyanStatus ZyanListInitEx(ZyanList* list, ZyanUSize element_size, ZyanMemberProcedure destructor,
ZyanAllocator* allocator)
{
if (!list || !element_size || !allocator)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
list->allocator = allocator;
list->size = 0;
list->element_size = element_size;
list->destructor = destructor;
list->head = ZYAN_NULL;
list->tail = ZYAN_NULL;
list->buffer = ZYAN_NULL;
list->capacity = 0;
list->first_unused = ZYAN_NULL;
return ZYAN_STATUS_SUCCESS;
}
|
// ZYAN_NO_LIBC
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/List.c#L140-L159
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanListGetHeadNode
|
ZyanStatus ZyanListGetHeadNode(const ZyanList* list, const ZyanListNode** node)
{
if (!list)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
*node = list->head;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Duplication */
/* ---------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------- */
/* Item access */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/List.c#L224-L234
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanListPushBack
|
ZyanStatus ZyanListPushBack(ZyanList* list, const void* item)
{
if (!list || !item)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZyanListNode* node;
ZYAN_CHECK(ZyanListAllocateNode(list, &node));
node->prev = list->tail;
node->next = ZYAN_NULL;
ZYAN_MEMCPY(ZYCORE_LIST_GET_NODE_DATA(node), item, list->element_size);
if (!list->head)
{
list->head = node;
list->tail = node;
} else
{
list->tail->next = node;
list->tail = node;
}
++list->size;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Insertion */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/List.c#L338-L364
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanListPopBack
|
ZyanStatus ZyanListPopBack(ZyanList* list)
{
if (!list)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (!list->tail)
{
return ZYAN_STATUS_INVALID_OPERATION;
}
ZyanListNode* const node = list->tail;
if (list->destructor)
{
list->destructor(ZYCORE_LIST_GET_NODE_DATA(node));
}
list->tail = node->prev;
if (list->tail)
{
list->tail->next = ZYAN_NULL;
}
if (list->head == node)
{
list->head = list->tail;
}
--list->size;
return ZyanListDeallocateNode(list, node);
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Deletion */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/List.c#L462-L492
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanListResize
|
ZyanStatus ZyanListResize(ZyanList* list, ZyanUSize size)
{
return ZyanListResizeEx(list, size, ZYAN_NULL);
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Searching */
/* ---------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------- */
/* Memory management */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/List.c#L556-L559
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanListGetSize
|
ZyanStatus ZyanListGetSize(const ZyanList* list, ZyanUSize* size)
{
if (!list)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
*size = list->size;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Information */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/List.c#L659-L669
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringInitEx
|
ZyanStatus ZyanStringInitEx(ZyanString* string, ZyanUSize capacity, ZyanAllocator* allocator,
ZyanU8 growth_factor, ZyanU8 shrink_threshold)
{
if (!string)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
string->flags = 0;
capacity = ZYAN_MAX(ZYAN_STRING_MIN_CAPACITY, capacity) + 1;
ZYAN_CHECK(ZyanVectorInitEx(&string->vector, sizeof(char), capacity, ZYAN_NULL, allocator,
growth_factor, shrink_threshold));
ZYAN_ASSERT(string->vector.capacity >= capacity);
// Some of the string code relies on `sizeof(char) == 1`
ZYAN_ASSERT(string->vector.element_size == 1);
*(char*)string->vector.data = '\0';
++string->vector.size;
return ZYAN_STATUS_SUCCESS;
}
|
// ZYAN_NO_LIBC
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L64-L84
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringDuplicateEx
|
ZyanStatus ZyanStringDuplicateEx(ZyanString* destination, const ZyanStringView* source,
ZyanUSize capacity, ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
{
if (!source || !source->string.vector.size)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
const ZyanUSize len = source->string.vector.size;
capacity = ZYAN_MAX(capacity, len - 1);
ZYAN_CHECK(ZyanStringInitEx(destination, capacity, allocator, growth_factor, shrink_threshold));
ZYAN_ASSERT(destination->vector.capacity >= len);
ZYAN_MEMCPY(destination->vector.data, source->string.vector.data,
source->string.vector.size - 1);
destination->vector.size = len;
ZYCORE_STRING_NULLTERMINATE(destination);
return ZYAN_STATUS_SUCCESS;
}
|
// ZYAN_NO_LIBC
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L135-L154
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringConcatEx
|
ZyanStatus ZyanStringConcatEx(ZyanString* destination, const ZyanStringView* s1,
const ZyanStringView* s2, ZyanUSize capacity, ZyanAllocator* allocator, ZyanU8 growth_factor,
ZyanU8 shrink_threshold)
{
if (!s1 || !s2 || !s1->string.vector.size || !s2->string.vector.size)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
const ZyanUSize len = s1->string.vector.size + s2->string.vector.size - 1;
capacity = ZYAN_MAX(capacity, len - 1);
ZYAN_CHECK(ZyanStringInitEx(destination, capacity, allocator, growth_factor, shrink_threshold));
ZYAN_ASSERT(destination->vector.capacity >= len);
ZYAN_MEMCPY(destination->vector.data, s1->string.vector.data, s1->string.vector.size - 1);
ZYAN_MEMCPY((char*)destination->vector.data + s1->string.vector.size - 1,
s2->string.vector.data, s2->string.vector.size - 1);
destination->vector.size = len;
ZYCORE_STRING_NULLTERMINATE(destination);
return ZYAN_STATUS_SUCCESS;
}
|
// ZYAN_NO_LIBC
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L196-L217
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringViewInsideView
|
ZyanStatus ZyanStringViewInsideView(ZyanStringView* view, const ZyanStringView* source)
{
if (!view || !source)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
view->string.vector.data = source->string.vector.data;
view->string.vector.size = source->string.vector.size;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Views */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L249-L260
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringGetChar
|
ZyanStatus ZyanStringGetChar(const ZyanStringView* string, ZyanUSize index, char* value)
{
if (!string || !value)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
// Don't allow direct access to the terminating '\0' character
if (index + 1 >= string->string.vector.size)
{
return ZYAN_STATUS_OUT_OF_RANGE;
}
const char* chr;
ZYAN_CHECK(ZyanVectorGetPointer(&string->string.vector, index, (const void**)&chr));
*value = *chr;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Character access */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L336-L354
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringInsert
|
ZyanStatus ZyanStringInsert(ZyanString* destination, ZyanUSize index, const ZyanStringView* source)
{
if (!destination || !source || !source->string.vector.size)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (index == destination->vector.size)
{
return ZyanStringAppend(destination, source);
}
// Don't allow insertion after the terminating '\0' character
if (index >= destination->vector.size)
{
return ZYAN_STATUS_OUT_OF_RANGE;
}
ZYAN_CHECK(ZyanVectorInsertRange(&destination->vector, index, source->string.vector.data,
source->string.vector.size - 1));
ZYCORE_STRING_ASSERT_NULLTERMINATION(destination);
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Insertion */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L392-L415
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringAppend
|
ZyanStatus ZyanStringAppend(ZyanString* destination, const ZyanStringView* source)
{
if (!destination || !source || !source->string.vector.size)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
const ZyanUSize len = destination->vector.size;
ZYAN_CHECK(ZyanVectorResize(&destination->vector, len + source->string.vector.size - 1));
ZYAN_MEMCPY((char*)destination->vector.data + len - 1, source->string.vector.data,
source->string.vector.size - 1);
ZYCORE_STRING_NULLTERMINATE(destination);
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Appending */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L453-L467
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringDelete
|
ZyanStatus ZyanStringDelete(ZyanString* string, ZyanUSize index, ZyanUSize count)
{
if (!string)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
// Don't allow removal of the terminating '\0' character
if (index + count >= string->vector.size)
{
return ZYAN_STATUS_OUT_OF_RANGE;
}
ZYAN_CHECK(ZyanVectorDeleteRange(&string->vector, index, count));
ZYCORE_STRING_NULLTERMINATE(string);
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Deletion */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L496-L513
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringLPos
|
ZyanStatus ZyanStringLPos(const ZyanStringView* haystack, const ZyanStringView* needle,
ZyanISize* found_index)
{
if (!haystack)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
return ZyanStringLPosEx(haystack, needle, found_index, 0, haystack->string.vector.size - 1);
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Searching */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L555-L564
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringCompare
|
ZyanStatus ZyanStringCompare(const ZyanStringView* s1, const ZyanStringView* s2, ZyanI32* result)
{
if (!s1 || !s2)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if (s1->string.vector.size < s2->string.vector.size)
{
*result = -1;
return ZYAN_STATUS_FALSE;
}
if (s1->string.vector.size > s2->string.vector.size)
{
*result = 1;
return ZYAN_STATUS_FALSE;
}
const char* const a = (char*)s1->string.vector.data;
const char* const b = (char*)s2->string.vector.data;
ZyanUSize i;
for (i = 0; (i + 1 < s1->string.vector.size) && (i + 1 < s2->string.vector.size); ++i)
{
if (a[i] == b[i])
{
continue;
}
break;
}
if (a[i] == b[i])
{
*result = 0;
return ZYAN_STATUS_TRUE;
}
if ((a[i] | 32) < (b[i] | 32))
{
*result = -1;
return ZYAN_STATUS_FALSE;
}
*result = 1;
return ZYAN_STATUS_FALSE;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Comparing */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L835-L879
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringToLowerCase
|
ZyanStatus ZyanStringToLowerCase(ZyanString* string)
{
if (!string)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
return ZyanStringToLowerCaseEx(string, 0, string->vector.size - 1);
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Case conversion */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L935-L943
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringResize
|
ZyanStatus ZyanStringResize(ZyanString* string, ZyanUSize size)
{
if (!string)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZYAN_CHECK(ZyanVectorResize(&string->vector, size + 1));
ZYCORE_STRING_NULLTERMINATE(string);
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Memory management */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L1021-L1032
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanStringGetCapacity
|
ZyanStatus ZyanStringGetCapacity(const ZyanString* string, ZyanUSize* capacity)
{
if (!string)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZYAN_ASSERT(string->vector.capacity >= 1);
*capacity = string->vector.capacity - 1;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Information */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/String.c#L1058-L1069
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorReallocate
|
static ZyanStatus ZyanVectorReallocate(ZyanVector* vector, ZyanUSize capacity)
{
ZYAN_ASSERT(vector);
ZYAN_ASSERT(vector->capacity >= ZYAN_VECTOR_MIN_CAPACITY);
ZYAN_ASSERT(vector->element_size);
ZYAN_ASSERT(vector->data);
if (!vector->allocator)
{
if (vector->capacity < capacity)
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
return ZYAN_STATUS_SUCCESS;
}
ZYAN_ASSERT(vector->allocator);
ZYAN_ASSERT(vector->allocator->reallocate);
if (capacity < ZYAN_VECTOR_MIN_CAPACITY)
{
if (vector->capacity > ZYAN_VECTOR_MIN_CAPACITY)
{
capacity = ZYAN_VECTOR_MIN_CAPACITY;
} else
{
return ZYAN_STATUS_SUCCESS;
}
}
vector->capacity = capacity;
ZYAN_CHECK(vector->allocator->reallocate(vector->allocator, &vector->data,
vector->element_size, vector->capacity));
return ZYAN_STATUS_SUCCESS;
}
|
/* ============================================================================================== */
/* Internal functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Helper functions */
/* ---------------------------------------------------------------------------------------------- */
/**
* Reallocates the internal buffer of the vector.
*
* @param vector A pointer to the `ZyanVector` instance.
* @param capacity The new capacity.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L84-L119
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorShiftLeft
|
static ZyanStatus ZyanVectorShiftLeft(ZyanVector* vector, ZyanUSize index, ZyanUSize count)
{
ZYAN_ASSERT(vector);
ZYAN_ASSERT(vector->element_size);
ZYAN_ASSERT(vector->data);
ZYAN_ASSERT(count > 0);
//ZYAN_ASSERT((ZyanISize)count - (ZyanISize)index + 1 >= 0);
const void* const source = ZYCORE_VECTOR_OFFSET(vector, index + count);
void* const dest = ZYCORE_VECTOR_OFFSET(vector, index);
const ZyanUSize size = (vector->size - index - count) * vector->element_size;
ZYAN_MEMMOVE(dest, source, size);
return ZYAN_STATUS_SUCCESS;
}
|
/**
* Shifts all elements starting at the specified `index` by the amount of `count` to the left.
*
* @param vector A pointer to the `ZyanVector` instance.
* @param index The start index.
* @param count The amount of shift operations.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L130-L144
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorShiftRight
|
static ZyanStatus ZyanVectorShiftRight(ZyanVector* vector, ZyanUSize index, ZyanUSize count)
{
ZYAN_ASSERT(vector);
ZYAN_ASSERT(vector->element_size);
ZYAN_ASSERT(vector->data);
ZYAN_ASSERT(count > 0);
ZYAN_ASSERT(vector->size + count <= vector->capacity);
const void* const source = ZYCORE_VECTOR_OFFSET(vector, index);
void* const dest = ZYCORE_VECTOR_OFFSET(vector, index + count);
const ZyanUSize size = (vector->size - index) * vector->element_size;
ZYAN_MEMMOVE(dest, source, size);
return ZYAN_STATUS_SUCCESS;
}
|
/**
* Shifts all elements starting at the specified `index` by the amount of `count` to the right.
*
* @param vector A pointer to the `ZyanVector` instance.
* @param index The start index.
* @param count The amount of shift operations.
*
* @return A zyan status code.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L155-L169
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorInitEx
|
ZyanStatus ZyanVectorInitEx(ZyanVector* vector, ZyanUSize element_size, ZyanUSize capacity,
ZyanMemberProcedure destructor, ZyanAllocator* allocator, ZyanU8 growth_factor,
ZyanU8 shrink_threshold)
{
if (!vector || !element_size || !allocator || (growth_factor < 1))
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZYAN_ASSERT(allocator->allocate);
vector->allocator = allocator;
vector->growth_factor = growth_factor;
vector->shrink_threshold = shrink_threshold;
vector->size = 0;
vector->capacity = ZYAN_MAX(ZYAN_VECTOR_MIN_CAPACITY, capacity);
vector->element_size = element_size;
vector->destructor = destructor;
vector->data = ZYAN_NULL;
return allocator->allocate(vector->allocator, &vector->data, vector->element_size,
vector->capacity);
}
|
// ZYAN_NO_LIBC
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L192-L214
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorDuplicateEx
|
ZyanStatus ZyanVectorDuplicateEx(ZyanVector* destination, const ZyanVector* source,
ZyanUSize capacity, ZyanAllocator* allocator, ZyanU8 growth_factor, ZyanU8 shrink_threshold)
{
if (!source)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
const ZyanUSize len = source->size;
capacity = ZYAN_MAX(capacity, len);
ZYAN_CHECK(ZyanVectorInitEx(destination, source->element_size, capacity, source->destructor,
allocator, growth_factor, shrink_threshold));
ZYAN_ASSERT(destination->capacity >= len);
ZYAN_MEMCPY(destination->data, source->data, len * source->element_size);
destination->size = len;
return ZYAN_STATUS_SUCCESS;
}
|
// ZYAN_NO_LIBC
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L280-L299
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorPushBack
|
ZyanStatus ZyanVectorPushBack(ZyanVector* vector, const void* element)
{
if (!vector || !element)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
ZYAN_ASSERT(vector->element_size);
ZYAN_ASSERT(vector->data);
if (ZYCORE_VECTOR_SHOULD_GROW(vector->size + 1, vector->capacity))
{
ZYAN_CHECK(ZyanVectorReallocate(vector,
ZYAN_MAX(1, (ZyanUSize)((vector->size + 1) * vector->growth_factor))));
}
void* const offset = ZYCORE_VECTOR_OFFSET(vector, vector->size);
ZYAN_MEMCPY(offset, element, vector->element_size);
++vector->size;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Insertion */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L422-L444
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorSwapElements
|
ZyanStatus ZyanVectorSwapElements(ZyanVector* vector, ZyanUSize index_first, ZyanUSize index_second)
{
if (!vector)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
if ((index_first >= vector->size) || (index_second >= vector->size))
{
return ZYAN_STATUS_OUT_OF_RANGE;
}
if (vector->size == vector->capacity)
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
ZYAN_ASSERT(vector->element_size);
ZYAN_ASSERT(vector->data);
ZyanU64* const t = ZYCORE_VECTOR_OFFSET(vector, vector->size);
ZyanU64* const a = ZYCORE_VECTOR_OFFSET(vector, index_first);
ZyanU64* const b = ZYCORE_VECTOR_OFFSET(vector, index_second);
ZYAN_MEMCPY(t, a, vector->element_size);
ZYAN_MEMCPY(a, b, vector->element_size);
ZYAN_MEMCPY(b, t, vector->element_size);
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Utils */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L535-L562
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorDelete
|
ZyanStatus ZyanVectorDelete(ZyanVector* vector, ZyanUSize index)
{
return ZyanVectorDeleteRange(vector, index, 1);
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Deletion */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L568-L571
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorFind
|
ZyanStatus ZyanVectorFind(const ZyanVector* vector, const void* element, ZyanISize* found_index,
ZyanEqualityComparison comparison)
{
if (!vector)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
return ZyanVectorFindEx(vector, element, found_index, comparison, 0, vector->size);
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Searching */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L642-L651
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorResize
|
ZyanStatus ZyanVectorResize(ZyanVector* vector, ZyanUSize size)
{
return ZyanVectorResizeEx(vector, size, ZYAN_NULL);
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Memory management */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L747-L750
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanVectorGetCapacity
|
ZyanStatus ZyanVectorGetCapacity(const ZyanVector* vector, ZyanUSize* capacity)
{
if (!vector)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
*capacity = vector->capacity;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Information */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Vector.c#L820-L830
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZycoreGetVersion
|
ZyanU64 ZycoreGetVersion(void)
{
return ZYCORE_VERSION;
}
|
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/Zycore.c#L33-L36
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanMemoryGetSystemPageSize
|
ZyanU32 ZyanMemoryGetSystemPageSize()
{
#if defined(ZYAN_WINDOWS)
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
return system_info.dwPageSize;
#elif defined(ZYAN_POSIX)
return sysconf(_SC_PAGE_SIZE);
#endif
}
|
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Memory.c#L47-L61
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanMemoryVirtualProtect
|
ZyanStatus ZyanMemoryVirtualProtect(void* address, ZyanUSize size,
ZyanMemoryPageProtection protection)
{
#if defined(ZYAN_WINDOWS)
DWORD old;
if (!VirtualProtect(address, size, protection, &old))
{
return ZYAN_STATUS_BAD_SYSTEMCALL;
}
#elif defined(ZYAN_POSIX)
if (mprotect(address, size, protection))
{
return ZYAN_STATUS_BAD_SYSTEMCALL;
}
#endif
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Memory management */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Memory.c#L83-L104
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanProcessFlushInstructionCache
|
ZyanStatus ZyanProcessFlushInstructionCache(void* address, ZyanUSize size)
{
#if defined(ZYAN_WINDOWS)
if (!FlushInstructionCache(GetCurrentProcess(), address, size))
{
return ZYAN_STATUS_BAD_SYSTEMCALL;
}
#elif defined(ZYAN_POSIX)
if (msync(address, size, MS_SYNC | MS_INVALIDATE))
{
return ZYAN_STATUS_BAD_SYSTEMCALL;
}
#endif
return ZYAN_STATUS_SUCCESS;
}
|
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Process.c#L51-L70
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanCriticalSectionInitialize
|
ZyanStatus ZyanCriticalSectionInitialize(ZyanCriticalSection* critical_section)
{
pthread_mutexattr_t attribute;
int error = pthread_mutexattr_init(&attribute);
if (error != 0)
{
if (error == ENOMEM)
{
return ZYAN_STATUS_NOT_ENOUGH_MEMORY;
}
return ZYAN_STATUS_BAD_SYSTEMCALL;
}
pthread_mutexattr_settype(&attribute, PTHREAD_MUTEX_RECURSIVE);
error = pthread_mutex_init(critical_section, &attribute);
pthread_mutexattr_destroy(&attribute);
if (error != 0)
{
if (error == EAGAIN)
{
return ZYAN_STATUS_OUT_OF_RESOURCES;
}
if (error == ENOMEM)
{
return ZYAN_STATUS_NOT_ENOUGH_MEMORY;
}
if (error == EPERM)
{
return ZYAN_STATUS_ACCESS_DENIED;
}
if ((error == EBUSY) || (error == EINVAL))
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
return ZYAN_STATUS_BAD_SYSTEMCALL;
}
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Critical Section */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Synchronization.c#L55-L94
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanCriticalSectionInitialize
|
ZyanStatus ZyanCriticalSectionInitialize(ZyanCriticalSection* critical_section)
{
InitializeCriticalSection(critical_section);
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Synchronization.c#L163-L168
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanTerminalEnableVT100
|
ZyanStatus ZyanTerminalEnableVT100(ZyanStandardStream stream)
{
if ((stream != ZYAN_STDSTREAM_OUT) && (stream != ZYAN_STDSTREAM_ERR))
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
#ifdef ZYAN_WINDOWS
// Get file descriptor
int file;
switch (stream)
{
case ZYAN_STDSTREAM_OUT:
file = _fileno(ZYAN_STDOUT);
break;
case ZYAN_STDSTREAM_ERR:
file = _fileno(ZYAN_STDERR);
break;
default:
ZYAN_UNREACHABLE;
}
if (file < 0)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
HANDLE const handle = (HANDLE)_get_osfhandle(file);
if (handle == INVALID_HANDLE_VALUE)
{
return ZYAN_STATUS_INVALID_ARGUMENT;
}
DWORD mode;
if (!GetConsoleMode(handle, &mode))
{
// The given standard stream is not bound to a terminal
return ZYAN_STATUS_INVALID_ARGUMENT;
}
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(handle, mode))
{
return ZYAN_STATUS_BAD_SYSTEMCALL;
}
#endif
return ZYAN_STATUS_SUCCESS;
}
|
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Terminal.c#L51-L98
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanThreadGetCurrentThread
|
ZyanStatus ZyanThreadGetCurrentThread(ZyanThread* thread)
{
*thread = pthread_self();
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Thread.c#L101-L106
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanThreadTlsAlloc
|
ZyanStatus ZyanThreadTlsAlloc(ZyanThreadTlsIndex* index, ZyanThreadTlsCallback destructor)
{
ZyanThreadTlsIndex value;
const int error = pthread_key_create(&value, destructor);
if (error != 0)
{
if (error == EAGAIN)
{
return ZYAN_STATUS_OUT_OF_RESOURCES;
}
if (error == ENOMEM)
{
return ZYAN_STATUS_NOT_ENOUGH_MEMORY;
}
return ZYAN_STATUS_BAD_SYSTEMCALL;
}
*index = value;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Thread Local Storage */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Thread.c#L123-L142
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanThreadGetCurrentThread
|
ZyanStatus ZyanThreadGetCurrentThread(ZyanThread* thread)
{
*thread = GetCurrentThread();
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Thread.c#L179-L184
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZyanThreadTlsAlloc
|
ZyanStatus ZyanThreadTlsAlloc(ZyanThreadTlsIndex* index, ZyanThreadTlsCallback destructor)
{
const ZyanThreadTlsIndex value = FlsAlloc(destructor);
if (value == FLS_OUT_OF_INDEXES)
{
return ZYAN_STATUS_OUT_OF_RESOURCES;
}
*index = value;
return ZYAN_STATUS_SUCCESS;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Thread Local Storage (TLS) */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/dependencies/zycore/src/API/Thread.c#L197-L207
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ExpectSuccess
|
static void ExpectSuccess(ZyanStatus status)
{
if (ZYAN_FAILED(status))
{
fprintf(stderr, "Something failed: 0x%08X\n", status);
exit(EXIT_FAILURE);
}
}
|
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/EncodeFromScratch.c#L43-L50
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
DisassembleBuffer
|
static void DisassembleBuffer(ZydisDecoder* decoder, ZyanU8* data, ZyanUSize length)
{
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SEGMENT, ZYAN_TRUE);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SIZE, ZYAN_TRUE);
// Replace the `ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_ABS` function that formats the absolute
// addresses
default_print_address_absolute = (ZydisFormatterFunc)&ZydisFormatterPrintAddressAbsolute;
ZydisFormatterSetHook(&formatter, ZYDIS_FORMATTER_FUNC_PRINT_ADDRESS_ABS,
(const void**)&default_print_address_absolute);
ZyanU64 runtime_address = 0x007FFFFFFF400000;
ZydisDecodedInstruction instruction;
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
char buffer[256];
while (ZYAN_SUCCESS(ZydisDecoderDecodeFull(decoder, data, length, &instruction, operands,
ZYDIS_MAX_OPERAND_COUNT_VISIBLE, ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY)))
{
ZYAN_PRINTF("%016" PRIX64 " ", runtime_address);
// We have to pass a `runtime_address` different to `ZYDIS_RUNTIME_ADDRESS_NONE` to
// enable printing of absolute addresses
ZydisFormatterFormatInstruction(&formatter, &instruction, operands,
instruction.operand_count_visible, &buffer[0], sizeof(buffer), runtime_address);
ZYAN_PRINTF(" %s\n", &buffer[0]);
data += instruction.length;
length -= instruction.length;
runtime_address += instruction.length;
}
}
|
/* ============================================================================================== */
/* Helper functions */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/Formatter01.c#L102-L136
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
main
|
int main(void)
{
if (ZydisGetVersion() != ZYDIS_VERSION)
{
fputs("Invalid zydis version\n", ZYAN_STDERR);
return EXIT_FAILURE;
}
ZyanU8 data[] =
{
0x48, 0x8B, 0x05, 0x39, 0x00, 0x13, 0x00, // mov rax, qword ptr ds:[<SomeModule.SomeData>]
0x50, // push rax
0xFF, 0x15, 0xF2, 0x10, 0x00, 0x00, // call qword ptr ds:[<SomeModule.SomeFunction>]
0x85, 0xC0, // test eax, eax
0x0F, 0x84, 0x00, 0x00, 0x00, 0x00, // jz 0x007FFFFFFF400016
0xE9, 0xE5, 0x0F, 0x00, 0x00 // jmp <SomeModule.EntryPoint>
};
ZydisDecoder decoder;
ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64);
DisassembleBuffer(&decoder, &data[0], sizeof(data));
return 0;
}
|
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/Formatter01.c#L142-L166
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
DisassembleBuffer
|
static void DisassembleBuffer(ZydisDecoder* decoder, ZyanU8* data, ZyanUSize length,
ZyanBool install_hooks)
{
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SEGMENT, ZYAN_TRUE);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SIZE, ZYAN_TRUE);
if (install_hooks)
{
default_print_mnemonic = (ZydisFormatterFunc)&ZydisFormatterPrintMnemonic;
ZydisFormatterSetHook(&formatter, ZYDIS_FORMATTER_FUNC_PRINT_MNEMONIC,
(const void**)&default_print_mnemonic);
default_format_operand_imm = (ZydisFormatterFunc)&ZydisFormatterFormatOperandIMM;
ZydisFormatterSetHook(&formatter, ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_IMM,
(const void**)&default_format_operand_imm);
}
ZyanU64 runtime_address = 0x007FFFFFFF400000;
ZydisDecodedInstruction instruction;
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZydisCustomUserData user_data;
char buffer[256];
while (ZYAN_SUCCESS(ZydisDecoderDecodeFull(decoder, data, length, &instruction, operands,
ZYDIS_MAX_OPERAND_COUNT_VISIBLE, ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY)))
{
ZYAN_PRINTF("%016" PRIX64 " ", runtime_address);
ZydisFormatterFormatInstructionEx(&formatter, &instruction, operands,
instruction.operand_count_visible, &buffer[0], sizeof(buffer), runtime_address,
&user_data);
ZYAN_PRINTF(" %s\n", &buffer[0]);
data += instruction.length;
length -= instruction.length;
runtime_address += instruction.length;
}
}
|
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Helper functions */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/Formatter02.c#L193-L232
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
main
|
int main(void)
{
if (ZydisGetVersion() != ZYDIS_VERSION)
{
fputs("Invalid zydis version\n", ZYAN_STDERR);
return EXIT_FAILURE;
}
ZyanU8 data[] =
{
// nop
0x90,
// cmpps xmm1, xmm4, 0x03
0x0F, 0xC2, 0xCC, 0x03,
// vcmppd xmm1, xmm2, xmm3, 0x17
0xC5, 0xE9, 0xC2, 0xCB, 0x17,
// vcmpps k2 {k7}, zmm2, dword ptr ds:[rax + rbx*4 + 0x100] {1to16}, 0x0F
0x62, 0xF1, 0x6C, 0x5F, 0xC2, 0x54, 0x98, 0x40, 0x0F
};
ZydisDecoder decoder;
ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64);
DisassembleBuffer(&decoder, &data[0], sizeof(data), ZYAN_FALSE);
ZYAN_PUTS("");
DisassembleBuffer(&decoder, &data[0], sizeof(data), ZYAN_TRUE);
return 0;
}
|
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/Formatter02.c#L238-L269
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
DisassembleBuffer
|
static void DisassembleBuffer(ZydisDecoder* decoder, ZyanU8* data, ZyanUSize length)
{
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SEGMENT, ZYAN_TRUE);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SIZE, ZYAN_TRUE);
ZyanU64 runtime_address = 0x007FFFFFFF400000;
ZydisDecodedInstruction instruction;
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
char buffer[256];
while (ZYAN_SUCCESS(ZydisDecoderDecodeFull(decoder, data, length, &instruction, operands,
ZYDIS_MAX_OPERAND_COUNT_VISIBLE, ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY)))
{
const ZydisFormatterToken* token;
if (ZYAN_SUCCESS(ZydisFormatterTokenizeInstruction(&formatter, &instruction, operands,
instruction.operand_count_visible , &buffer[0], sizeof(buffer), runtime_address,
&token)))
{
ZydisTokenType token_type;
ZyanConstCharPointer token_value = ZYAN_NULL;
while (token)
{
ZydisFormatterTokenGetValue(token, &token_type, &token_value);
printf("ZYDIS_TOKEN_%17s (%02X): \"%s\"\n", TOKEN_TYPES[token_type], token_type,
token_value);
if (!ZYAN_SUCCESS(ZydisFormatterTokenNext(&token)))
{
token = ZYAN_NULL;
}
}
}
data += instruction.length;
length -= instruction.length;
runtime_address += instruction.length;
}
}
|
/* ============================================================================================== */
/* Helper functions */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/Formatter03.c#L64-L103
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
main
|
int main(void)
{
if (ZydisGetVersion() != ZYDIS_VERSION)
{
fputs("Invalid zydis version\n", ZYAN_STDERR);
return EXIT_FAILURE;
}
ZyanU8 data[] =
{
// vcmpps k2 {k7}, zmm2, dword ptr ds:[rax + rbx*4 + 0x100] {1to16}, 0x0F
0x62, 0xF1, 0x6C, 0x5F, 0xC2, 0x54, 0x98, 0x40, 0x0F
};
ZydisDecoder decoder;
ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64);
DisassembleBuffer(&decoder, &data[0], sizeof(data));
return 0;
}
|
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/Formatter03.c#L109-L129
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ExpectSuccess
|
static void ExpectSuccess(ZyanStatus status)
{
if (ZYAN_FAILED(status))
{
fprintf(stderr, "Something failed: 0x%08X\n", status);
exit(EXIT_FAILURE);
}
}
|
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/RewriteCode.c#L49-L56
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
AdjustProcessAndThreadPriority
|
static void AdjustProcessAndThreadPriority(void)
{
#if defined(ZYAN_WINDOWS)
SYSTEM_INFO info;
GetSystemInfo(&info);
if (info.dwNumberOfProcessors > 1)
{
if (!SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR)1))
{
ZYAN_FPRINTF(ZYAN_STDERR, "%sWarning: Could not set thread affinity mask%s\n",
CVT100_ERR(ZYAN_VT100SGR_FG_YELLOW), CVT100_ERR(ZYAN_VT100SGR_RESET));
}
if (!SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS))
{
ZYAN_FPRINTF(ZYAN_STDERR, "%sWarning: Could not set process priority class%s\n",
CVT100_ERR(ZYAN_VT100SGR_FG_YELLOW), CVT100_ERR(ZYAN_VT100SGR_RESET));
}
if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL))
{
ZYAN_FPRINTF(ZYAN_STDERR, "%sWarning: Could not set thread priority class%s\n",
CVT100_ERR(ZYAN_VT100SGR_FG_YELLOW), CVT100_ERR(ZYAN_VT100SGR_RESET));
}
}
#elif defined(ZYAN_LINUX) || defined(ZYAN_FREEBSD)
pthread_t thread = pthread_self();
#if defined(ZYAN_LINUX)
cpu_set_t cpus;
#else // FreeBSD
cpuset_t cpus;
#endif
CPU_ZERO(&cpus);
CPU_SET(0, &cpus);
if (pthread_setaffinity_np(thread, sizeof(cpus), &cpus))
{
ZYAN_FPRINTF(ZYAN_STDERR, "%sWarning: Could not set thread affinity mask%s\n",
CVT100_ERR(ZYAN_VT100SGR_FG_YELLOW), CVT100_ERR(ZYAN_VT100SGR_RESET));
}
#endif
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Process & Thread Priority */
/* ---------------------------------------------------------------------------------------------- */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/ZydisPerfTest.c#L174-L218
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
main
|
int main(int argc, char** argv)
{
// Enable VT100 escape sequences on Windows, if the output is not redirected
g_vt100_stdout = (ZyanTerminalIsTTY(ZYAN_STDSTREAM_OUT) == ZYAN_STATUS_TRUE) &&
ZYAN_SUCCESS(ZyanTerminalEnableVT100(ZYAN_STDSTREAM_OUT));
g_vt100_stderr = (ZyanTerminalIsTTY(ZYAN_STDSTREAM_ERR) == ZYAN_STATUS_TRUE) &&
ZYAN_SUCCESS(ZyanTerminalEnableVT100(ZYAN_STDSTREAM_ERR));
if (ZydisGetVersion() != ZYDIS_VERSION)
{
ZYAN_FPRINTF(ZYAN_STDERR, "%sInvalid zydis version%s\n",
CVT100_ERR(COLOR_ERROR), CVT100_ERR(ZYAN_VT100SGR_RESET));
return EXIT_FAILURE;
}
if (argc < 3 || (ZYAN_STRCMP(argv[1], "-test") && ZYAN_STRCMP(argv[1], "-generate")))
{
ZYAN_FPRINTF(ZYAN_STDERR, "%sUsage: %s -[test|generate] [directory]%s\n",
CVT100_ERR(COLOR_ERROR), (argc > 0 ? argv[0] : "PerfTest"),
CVT100_ERR(ZYAN_VT100SGR_RESET));
return EXIT_FAILURE;
}
ZyanBool generate = ZYAN_FALSE;
if (!ZYAN_STRCMP(argv[1], "-generate"))
{
generate = ZYAN_TRUE;
}
const char* directory = argv[2];
static const struct
{
const char* encoding;
const char* filename;
} tests[7] =
{
{ "DEFAULT", "enc_default.dat" },
{ "3DNOW" , "enc_3dnow.dat" },
{ "XOP" , "enc_xop.dat" },
{ "VEX_C4" , "enc_vex_c4.dat" },
{ "VEX_C5" , "enc_vex_c5.dat" },
{ "EVEX" , "enc_evex.dat" },
{ "MVEX" , "enc_mvex.dat" }
};
if (generate)
{
time_t t;
srand((unsigned)time(&t));
} else
{
AdjustProcessAndThreadPriority();
}
for (ZyanU8 i = 0; i < ZYAN_ARRAY_LENGTH(tests); ++i)
{
FILE* file;
const ZyanUSize len = strlen(directory);
char buf[1024];
strncpy(&buf[0], directory, sizeof(buf) - 1);
if (generate)
{
file = fopen(strncat(buf, tests[i].filename, sizeof(buf) - len - 1), "wb");
} else
{
file = fopen(strncat(buf, tests[i].filename, sizeof(buf) - len - 1), "rb");
}
if (!file)
{
ZYAN_FPRINTF(ZYAN_STDERR, "%sCould not open file \"%s\": %s%s\n",
CVT100_ERR(COLOR_ERROR), &buf[0], strerror(ZYAN_ERRNO),
CVT100_ERR(ZYAN_VT100SGR_RESET));
continue;
}
if (generate)
{
ZYAN_PRINTF("Generating %s%s%s ...\n", CVT100_OUT(COLOR_VALUE_B), tests[i].encoding,
CVT100_OUT(ZYAN_VT100SGR_RESET));
GenerateTestData(file, i);
} else
{
fseek(file, 0L, SEEK_END);
const long length = ftell(file);
void* buffer = malloc(length);
if (!buffer)
{
ZYAN_FPRINTF(ZYAN_STDERR,
"%sFailed to allocate %" PRIu64 " bytes on the heap%s\n",
CVT100_ERR(COLOR_ERROR), (ZyanU64)length, CVT100_ERR(ZYAN_VT100SGR_RESET));
goto NextFile2;
}
rewind(file);
if (fread(buffer, 1, length, file) != (ZyanUSize)length)
{
ZYAN_FPRINTF(ZYAN_STDERR,
"%sCould not read %" PRIu64 " bytes from file \"%s\"%s\n",
CVT100_ERR(COLOR_ERROR), (ZyanU64)length, &buf[0],
CVT100_ERR(ZYAN_VT100SGR_RESET));
goto NextFile1;
}
ZYAN_PRINTF("%sTesting %s%s%s ...\n", CVT100_OUT(ZYAN_VT100SGR_FG_MAGENTA),
CVT100_OUT(ZYAN_VT100SGR_FG_BRIGHT_MAGENTA), tests[i].encoding,
CVT100_OUT(COLOR_DEFAULT));
TestPerformance(buffer, length, ZYAN_TRUE , ZYAN_FALSE, ZYAN_FALSE, ZYAN_FALSE);
TestPerformance(buffer, length, ZYAN_FALSE, ZYAN_FALSE, ZYAN_FALSE, ZYAN_FALSE);
// TestPerformance(buffer, length, ZYAN_FALSE, ZYAN_FALSE, ZYAN_FALSE, ZYAN_TRUE);
TestPerformance(buffer, length, ZYAN_FALSE, ZYAN_TRUE , ZYAN_FALSE, ZYAN_FALSE);
// TestPerformance(buffer, length, ZYAN_FALSE, ZYAN_TRUE , ZYAN_FALSE, ZYAN_TRUE);
TestPerformance(buffer, length, ZYAN_FALSE, ZYAN_TRUE , ZYAN_TRUE , ZYAN_FALSE);
// TestPerformance(buffer, length, ZYAN_FALSE, ZYAN_TRUE , ZYAN_TRUE , ZYAN_TRUE);
ZYAN_PUTS("");
NextFile1:
free(buffer);
}
NextFile2:
fclose(file);
}
return 0;
}
|
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/ZydisPerfTest.c#L460-L585
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
Print
|
VOID
Print(
_In_ PCCH Format,
_In_ ...
)
{
CHAR message[512];
va_list argList;
va_start(argList, Format);
const int n = _vsnprintf_s(message, sizeof(message), sizeof(message) - 1, Format, argList);
message[n] = '\0';
vDbgPrintExWithPrefix("[ZYDIS] ", DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, message, argList);
va_end(argList);
}
|
/* ============================================================================================== */
/* Helper functions */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/ZydisWinKernel.c#L75-L88
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
DriverEntry
|
_Use_decl_annotations_
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
{
PAGED_CODE();
UNREFERENCED_PARAMETER(RegistryPath);
if (ZydisGetVersion() != ZYDIS_VERSION)
{
Print("Invalid zydis version\n");
return STATUS_UNKNOWN_REVISION;
}
// Get the driver's image base and PE headers
ULONG_PTR imageBase;
RtlPcToFileHeader((PVOID)DriverObject->DriverInit, (PVOID*)&imageBase);
if (imageBase == 0)
return STATUS_DRIVER_ENTRYPOINT_NOT_FOUND;
const PIMAGE_NT_HEADERS ntHeaders = RtlImageNtHeader((PVOID)imageBase);
if (ntHeaders == NULL)
return STATUS_INVALID_IMAGE_FORMAT;
// Get the section headers of the INIT section
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(ntHeaders);
PIMAGE_SECTION_HEADER initSection = NULL;
for (USHORT i = 0; i < ntHeaders->FileHeader.NumberOfSections; ++i)
{
if (memcmp(section->Name, "INIT", sizeof("INIT") - 1) == 0)
{
initSection = section;
break;
}
section++;
}
if (initSection == NULL)
return STATUS_NOT_FOUND;
// Get the RVAs of the entry point and import directory. If the import directory lies within the INIT section,
// stop disassembling when its address is reached. Otherwise, disassemble until the end of the INIT section.
const ULONG entryPointRva = (ULONG)((ULONG_PTR)DriverObject->DriverInit - imageBase);
const ULONG importDirRva = ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
SIZE_T length = initSection->VirtualAddress + initSection->SizeOfRawData - entryPointRva;
if (importDirRva > entryPointRva && importDirRva > initSection->VirtualAddress &&
importDirRva < initSection->VirtualAddress + initSection->SizeOfRawData)
length = importDirRva - entryPointRva;
Print("Driver image base: 0x%p, size: 0x%X\n", (PVOID)imageBase, ntHeaders->OptionalHeader.SizeOfImage);
Print("Entry point RVA: 0x%X (0x%p)\n", entryPointRva, DriverObject->DriverInit);
// Initialize Zydis decoder and formatter
ZydisDecoder decoder;
#ifdef _M_AMD64
if (!ZYAN_SUCCESS(ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64)))
#else
if (!ZYAN_SUCCESS(ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_COMPAT_32, ZYDIS_STACK_WIDTH_32)))
#endif
return STATUS_DRIVER_INTERNAL_ERROR;
ZydisFormatter formatter;
if (!ZYAN_SUCCESS(ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL)))
return STATUS_DRIVER_INTERNAL_ERROR;
SIZE_T readOffset = 0;
ZydisDecodedInstruction instruction;
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZyanStatus status;
CHAR printBuffer[128];
// Start the decode loop
while ((status = ZydisDecoderDecodeFull(&decoder,
(PVOID)(imageBase + entryPointRva + readOffset), length - readOffset, &instruction,
operands, ZYDIS_MAX_OPERAND_COUNT_VISIBLE, ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY)) !=
ZYDIS_STATUS_NO_MORE_DATA)
{
NT_ASSERT(ZYAN_SUCCESS(status));
if (!ZYAN_SUCCESS(status))
{
readOffset++;
continue;
}
// Format and print the instruction
const ZyanU64 instrAddress = (ZyanU64)(imageBase + entryPointRva + readOffset);
ZydisFormatterFormatInstruction(
&formatter, &instruction, operands, instruction.operand_count_visible, printBuffer,
sizeof(printBuffer), instrAddress);
Print("+%-4X 0x%-16llX\t\t%hs\n", (ULONG)readOffset, instrAddress, printBuffer);
readOffset += instruction.length;
}
// Return an error status so that the driver does not have to be unloaded after running.
return STATUS_UNSUCCESSFUL;
}
|
/* ============================================================================================== */
/* Entry point */
/* ============================================================================================== */
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/examples/ZydisWinKernel.c#L94-L191
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZydisInputPeek
|
static ZyanStatus ZydisInputPeek(ZydisDecoderState* state,
ZydisDecodedInstruction* instruction, ZyanU8* value)
{
ZYAN_ASSERT(state);
ZYAN_ASSERT(instruction);
ZYAN_ASSERT(value);
if (instruction->length >= ZYDIS_MAX_INSTRUCTION_LENGTH)
{
return ZYDIS_STATUS_INSTRUCTION_TOO_LONG;
}
if (state->buffer_len > 0)
{
*value = state->buffer[0];
return ZYAN_STATUS_SUCCESS;
}
return ZYDIS_STATUS_NO_MORE_DATA;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Internal functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Input helper functions */
/* ---------------------------------------------------------------------------------------------- */
/**
* Reads one byte from the current read-position of the input data-source.
*
* @param state A pointer to the `ZydisDecoderState` struct.
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param value A pointer to the memory that receives the byte from the input data-source.
*
* @return A zyan status code.
*
* This function may fail, if the `ZYDIS_MAX_INSTRUCTION_LENGTH` limit got exceeded, or no more
* data is available.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/src/Decoder.c#L246-L265
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZydisInputSkip
|
static void ZydisInputSkip(ZydisDecoderState* context, ZydisDecodedInstruction* instruction)
{
ZYAN_ASSERT(context);
ZYAN_ASSERT(instruction);
ZYAN_ASSERT(instruction->length < ZYDIS_MAX_INSTRUCTION_LENGTH);
++instruction->length;
++context->buffer;
--context->buffer_len;
}
|
/**
* Increases the read-position of the input data-source by one byte.
*
* @param context A pointer to the `ZydisDecoderContext` instance
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
*
* This function is supposed to get called ONLY after a successful call of `ZydisInputPeek`.
*
* This function increases the `length` field of the `ZydisDecodedInstruction` struct by one.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/src/Decoder.c#L277-L286
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZydisInputNext
|
static ZyanStatus ZydisInputNext(ZydisDecoderState* state,
ZydisDecodedInstruction* instruction, ZyanU8* value)
{
ZYAN_ASSERT(state);
ZYAN_ASSERT(instruction);
ZYAN_ASSERT(value);
if (instruction->length >= ZYDIS_MAX_INSTRUCTION_LENGTH)
{
return ZYDIS_STATUS_INSTRUCTION_TOO_LONG;
}
if (state->buffer_len > 0)
{
*value = state->buffer++[0];
++instruction->length;
--state->buffer_len;
return ZYAN_STATUS_SUCCESS;
}
return ZYDIS_STATUS_NO_MORE_DATA;
}
|
/**
* Reads one byte from the current read-position of the input data-source and increases
* the read-position by one byte afterwards.
*
* @param state A pointer to the `ZydisDecoderState` struct.
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param value A pointer to the memory that receives the byte from the input data-source.
*
* @return A zyan status code.
*
* This function acts like a subsequent call of `ZydisInputPeek` and `ZydisInputSkip`.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/src/Decoder.c#L300-L321
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZydisInputNextBytes
|
static ZyanStatus ZydisInputNextBytes(ZydisDecoderState* state,
ZydisDecodedInstruction* instruction, ZyanU8* value, ZyanU8 number_of_bytes)
{
ZYAN_ASSERT(state);
ZYAN_ASSERT(instruction);
ZYAN_ASSERT(value);
if (instruction->length + number_of_bytes > ZYDIS_MAX_INSTRUCTION_LENGTH)
{
return ZYDIS_STATUS_INSTRUCTION_TOO_LONG;
}
if (state->buffer_len >= number_of_bytes)
{
instruction->length += number_of_bytes;
ZYAN_MEMCPY(value, state->buffer, number_of_bytes);
state->buffer += number_of_bytes;
state->buffer_len -= number_of_bytes;
return ZYAN_STATUS_SUCCESS;
}
return ZYDIS_STATUS_NO_MORE_DATA;
}
|
/**
* Reads a variable amount of bytes from the current read-position of the input
* data-source and increases the read-position by specified amount of bytes afterwards.
*
* @param state A pointer to the `ZydisDecoderState` struct.
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param value A pointer to the memory that receives the byte from the input
* data-source.
* @param number_of_bytes The number of bytes to read from the input data-source.
*
* @return A zyan status code.
*
* This function acts like a subsequent call of `ZydisInputPeek` and `ZydisInputSkip`.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/src/Decoder.c#L337-L361
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
BugChecker
|
github_2023
|
vitoplantamura
|
c
|
ZydisDecodeREX
|
static void ZydisDecodeREX(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction,
ZyanU8 data)
{
ZYAN_ASSERT(instruction);
ZYAN_ASSERT((data & 0xF0) == 0x40);
instruction->attributes |= ZYDIS_ATTRIB_HAS_REX;
instruction->raw.rex.W = (data >> 3) & 0x01;
instruction->raw.rex.R = (data >> 2) & 0x01;
instruction->raw.rex.X = (data >> 1) & 0x01;
instruction->raw.rex.B = (data >> 0) & 0x01;
// Update internal fields
context->vector_unified.W = instruction->raw.rex.W;
context->vector_unified.R = instruction->raw.rex.R;
context->vector_unified.X = instruction->raw.rex.X;
context->vector_unified.B = instruction->raw.rex.B;
}
|
/* ---------------------------------------------------------------------------------------------- */
/* Decode functions */
/* ---------------------------------------------------------------------------------------------- */
/**
* Decodes the `REX`-prefix.
*
* @param context A pointer to the `ZydisDecoderContext` struct.
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param data The `REX` byte.
*/
|
https://github.com/vitoplantamura/BugChecker/blob/8b81e76efe457b59be3a6e752efd43916ba0cabb/dependencies/zydis/src/Decoder.c#L374-L391
|
8b81e76efe457b59be3a6e752efd43916ba0cabb
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.