c

Why is WSAConnect working and connect(); not?

淺唱寂寞╮ 提交于 2021-02-19 07:33:50
问题 I'm experimenting with some reverse shell code in C. It is working but only if I use WSAConnect() and WSASocket() . If I use socket() or connect() instead, it's not working. Why is this? I always use connect() instead of WSAConnect() , and socket() instead of WSASocket() . I know I am missing something. #include <winsock2.h> #include <stdio.h> #pragma comment(lib, "ws2_32.lib") WSADATA wsa; SOCKET sock; struct sockaddr_in server; STARTUPINFO sinfo; PROCESS_INFORMATION pinfo; int main(int argc

Calling a c-method with a c-style array as a parameter from C# .NET

我的梦境 提交于 2021-02-19 07:25:11
问题 I have a method defined in an unmanaged DLL: int foo(somestruct * vector, int size) How can I call this method from C#? Essentially, I want to complete the following snippet in my code: [StructLayout(LayoutKind.Sequential), Serializable] public struct somestruct { //Whatever. }; [DLLImport("some.dll")] public static extern int foo( ???? ); Thanks. 回答1: It's much simpler than you think. [DLLImport("some.dll")] public static extern int foo(somestruct[] vector, int size); The one thing to

Passing array from java to dll function with JNA

为君一笑 提交于 2021-02-19 07:21:29
问题 I want to pass Java array as parameter to c dll throw JNA , here is my code : import com.sun.jna.*; public class Javatest { public interface CLibrary extends Library { CLibrary INSTANCE = (CLibrary) Native.loadLibrary( "test", CLibrary.class); void test(Pointer p,int width); } public static void main(String[] args) { Pointer p = new Memory(5*Native.getNativeSize(Double.TYPE)); for (int i = 0; i < 5; i++) { p.setDouble(i*Native.getNativeSize(Double.TYPE),5); } CLibrary.INSTANCE.test(p,5); } }

does the c preprocessor handle floating point math constants

只谈情不闲聊 提交于 2021-02-19 07:12:44
问题 Say that I have #define A 23.9318; #define B 0.330043; #define C 5.220628; I want to do const unsigned result = (unsigned)(0x01000000 * ( A * B / C )); // unsigned is 32 bit What I hope for is to have result with fixed decimal representation of the floating point calculations. I cannot pre combine A,B,C together as their definition is not part of my code and I need it to work if they are changed. 回答1: No, the standard C preprocessor operations do not perform floating-point arithmetic. A C

Makefile Dependencies, What Should Be a Dependency?

冷暖自知 提交于 2021-02-19 06:57:08
问题 I have a conceptual question regarding makefile dependencies and this is because I see inconsistency online about this. Let's say I have the following files: main.cpp uses-> my_math.cpp and my_strings.cpp my_math.cpp uses-> my_math.h my_strings.cpp uses-> my_strings.h If I have a makefile, with the general outlay of: program: $(all_objs) g++ $(all_objs) -o program main.o: ... ....... my_math.o: ... ....... my_strings.o: ... ....... I don't know what should go into each dependency. Like, math

Extracting archive file in linker script

ぐ巨炮叔叔 提交于 2021-02-19 06:47:06
问题 I am trying to deal with a problem like the following one: Assume that I have a library libxyz.a created from: /* main.c */ int main(void) { int a; } compiled and archived with: gcc -c main.c -o abc.o && ar cr libxyz.a abc.o How do I have to write linker script in order to put abc.o exactly where it is expected to be? I was trying to handle it in such way: /* script.ld */ SEARCH_DIR(.) INPUT(-lxyz) SECTIONS { .text : { xyz:abc(.text) } .data : { xyz:abc(.data) } .bss : { xyz:abc(.bss) } } but

How to perform a Real to Complex Transformation with cuFFT

。_饼干妹妹 提交于 2021-02-19 06:41:25
问题 The following code has been adapted from here to apply to a single 1D transformation using cufftPlan1d. Ultimately I want to perform a batched in place R2C transformation, but code below perfroms a single transformation using a separate input and output array. How can adapt this code to perform a the transformation inplace, therefore reducing the amount of memory allocated on the device? Thanks Cuda 6.5 - Note: I'm running the code from a mexFunction in MATLAB 2015a Code: #include <stdlib.h>

GCC placing register args on the stack with a gap below local variables?

烂漫一生 提交于 2021-02-19 06:22:28
问题 I tried to look at the assembly code for a very simple program. int func(int x) { int z = 1337; return z; } With GCC -O0, every C variable has a memory address that's not optimized away, so gcc spills its register arg: (Godbolt, gcc5.5 -O0 -fverbose-asm) func: pushq %rbp # movq %rsp, %rbp #, movl %edi, -20(%rbp) # x, x movl $1337, -4(%rbp) #, z movl -4(%rbp), %eax # z, D.2332 popq %rbp # ret What is the reason that the function parameter x gets placed on the stack below the local variables?

GCC placing register args on the stack with a gap below local variables?

为君一笑 提交于 2021-02-19 06:22:26
问题 I tried to look at the assembly code for a very simple program. int func(int x) { int z = 1337; return z; } With GCC -O0, every C variable has a memory address that's not optimized away, so gcc spills its register arg: (Godbolt, gcc5.5 -O0 -fverbose-asm) func: pushq %rbp # movq %rsp, %rbp #, movl %edi, -20(%rbp) # x, x movl $1337, -4(%rbp) #, z movl -4(%rbp), %eax # z, D.2332 popq %rbp # ret What is the reason that the function parameter x gets placed on the stack below the local variables?

execve() failing to launch program in C

ぃ、小莉子 提交于 2021-02-19 06:16:08
问题 I am trying to spawn a new process using execve() from unistd.h on Linux. I have tried passing it the following parameters execve("/bin/ls", "/bin/ls", NULL); but get no result. I do not get an error either, the program just exits. Is there a reason why this is happening? I have tried launching it as root and regular user. The reason I need to use execve() is because I am trying to get it to work in an assembly call like so program: db "/bin/ls",0 mov eax, 0xb mov ebx, program mov ecx,