char *chBuff = new char[nBufferSize];
::SecureZeroMemory(chBuff, sizeof(chBuff));
I used the above code but get the following error
Wrong sizeof argument (SIZEOF_MISMATCH)
suspicious_sizeof: Passing argument chBuff of type char * and argument 4UL /* sizeof (chBuff) */ to function RtlSecureZeroMemory is suspicious.
Should I typecast? If so how?
syntax of SecureZeroMemory:
PVOID SecureZeroMemory(
_In_ PVOID ptr,
_In_ SIZE_T cnt
);
sizeof(char *) will provide you size of a pointer, instead, use the following:
char *chBuff = new char[nBufferSize];
::SecureZeroMemory(chBuff, sizeof(char)*nBufferSize);
Related
What is the correct syntax of a struct with char arrays ?
the nvsName gives me an error while compiling
And: is there another way to get initialize a value if the type is unknown ? Here I use the void*.
typedef struct
{
char nvsName[];
uint8_t type;
void* p;
} NVS_CONFIG;
NVS_CONFIG nvs = {'123',0,(void*)VdmConfig.configFlash.netConfig.staticIp};
your code contains multiple problems:
first : '123' is characther constant (see : wikipedia) not a string as you would expect with "123" and characther constant is an int.
second : nvsNames shoud be a pointer or have a constant size otherwise your code will not compile.
typedef struct
{
char * nvsName;
uint8_t type;
void* p;
} NVS_CONFIG;
NVS_CONFIG nvs = {"123",0,(void*)VdmConfig.configFlash.netConfig.staticIp};
should at least fix the probems you currently have.
When calling hci_inquiry how do I know/control if responses are of type inquiry_info, inquiry_info_with_rssi or inquiry_info_with_rssi_and_pscan_mode?
As you can see in the file hci_lib.h, in the prototype, the fifth argument is a double pointer to your inquiry_info array of size num_rsp.
int hci_inquiry(int dev_id, int len, int num_rsp, const uint8_t *lap, inquiry_info **ii, long flags);
inquiry_info_with_rssi and inquiry_info_with_rssi_and_pscan_mode are quite different structures so if you mistakenly use them you will have unexpected results.
I am trying to figure out what files my editor is watching on.
I have learnt that count the number of inotify fds from /proc/${PID}/fd is possible, and my question is: Is it possible to dump the list of watched inodes by one process?
UPDATE:
I have updated one working solution, and thanks for a helpful reference here.
UPDATE 2: well, recently I found kallsyms_lookup_name (and more symbols) not export since Linux Kernel v5.7, so I decide to update my own solution if anyone else cares.
Solved.
With the help of kprobe mechanism used in khook , I just simply hook the __x64_sys_inotify_add_watch and use user_path_at to steal the dentry.
The code snippet is listed below, and my working solution is provided here.
#define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */
#define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */
//regs->(di, si, dx, r10), reference: arch/x86/include/asm/syscall_wrapper.h#L125
//SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname, u32, mask)
KHOOK_EXT(long, __x64_sys_inotify_add_watch, const struct pt_regs *);
static long khook___x64_sysinotify_add_watch(const struct pt_regs *regs)
{
int wd;
struct path path;
unsigned int flags = 0;
char buf[PATH_MAX];
char *pname;
// decode the registers
int fd = (int) regs->di;
const char __user *pathname = (char __user *) regs->si;
u32 mask = (u32) regs->dx;
// do the original syscall
wd = KHOOK_ORIGIN(__x64_sys_inotify_add_watch, regs);
// get the pathname
if (!(mask & IN_DONT_FOLLOW))
flags |= LOOKUP_FOLLOW;
if (mask & IN_ONLYDIR)
flags |= LOOKUP_DIRECTORY;
if ( wd>=0 && (user_path_at(AT_FDCWD, pathname, flags, &path)==0) )
{
pname = dentry_path_raw(path.dentry, buf, PATH_MAX); //"pname" points to "buf[PATH_MAX]"
path_put(&path);
printk("%s, PID %d add (%d,%d): %s\n", current->comm, task_pid_nr(current), fd, wd, pname);
}
return wd;
}
I need the GNU Linux Code of the function
error_t argp_parse(const struct argp *__restrict __argp,int,char **__restrict,unsigned __flags,int * __arg_index,void *__restrict input)
If someone know where to get or have it ,please send it to me.
Thanks very much !!
Part of glibc, so easily found following the links at gnu.org:
From http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=argp/argp-parse.c;hb=e07bb02a4f9e7d98f79f428a661c5b982286869d:
/* Parse the options strings in ARGC & ARGV according to the argp in ARGP.
FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the
index in ARGV of the first unparsed option is returned in it. If an
unknown option is present, EINVAL is returned; if some parser routine
returned a non-zero value, it is returned; otherwise 0 is returned. */
error_t
__argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
int *end_index, void *input)
{
error_t err;
struct parser parser;
…
How to Convert char* to LPWSTR in VC++ ?
LPNETRESOURCEW nr = NULL;
memset(&nr, 0, sizeof (NETRESOURCE));
nr->lpLocalName = strDriveLetter.GetBuffer(strDriveLetter.GetLength()); // this line giving me error "Cannot Convert char* to LPWSTR"
Any help is appreciated.
Thanks.
Use MultiByteToWideChar function;
const char* msg = "foobarbaz";
int len = strlen(msg) + 1;
wchar_t *w_msg = new wchar_t[len];
memset(w_msg, 0, len);
MultiByteToWideChar(CP_ACP, NULL, msg, -1, w_msg, len);
memset(&nr, 0, sizeof (NETRESOURCE)); here nr is a NULL pointer. This is not correct. You should have nr point to a valid memory first by either using explicit allocation like new or on allocate on stack.