flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > [c help] called object is not a function or function pointer |
Author |
|
revolution 21 May 2016, 05:53
Perhaps your google search box is broken? Hehe. I took less than 20 seconds to find an answer. I thought about not posting it but that would be cruel. So since the work is done:
http://stackoverflow.com/questions/28901223/c-casting-char-array-to-an-integer-pointer |
|||
21 May 2016, 05:53 |
|
kerr 21 May 2016, 06:39
revolution wrote: Perhaps your google search box is broken? Hehe. I took less than 20 seconds to find an answer. I thought about not posting it but that would be cruel. So since the work is done: oh cronies ! you speak is not what i want! i have read this post! just not know! where is my program error! _________________ I hope we will be good friends. |
|||
21 May 2016, 06:39 |
|
Tyler 21 May 2016, 07:09
Oh man, you're just missing a semicolon (at the end of your string). Lol, that's an annoying mistake to spend a lot of time fixing.
Btw, I tested it and it segfaulted. I'm guessing either your code is buggy or the data section might be marked non-executable on my OS (Linux x64). If all you want is to link to some assembly, there are much easier ways to go about this. revolution, he's trying to cast to a function pointer, so he can call the array as a function. |
|||
21 May 2016, 07:09 |
|
revolution 21 May 2016, 07:19
Tyler wrote: Oh man, you're just missing a semicolon (at the end of your string). Lol, that's an annoying mistake to spend a lot of time fixing. Tyler wrote: revolution, he's trying to cast to a function pointer, so he can call the array as a function. |
|||
21 May 2016, 07:19 |
|
Tyler 21 May 2016, 07:30
revolution wrote: C is so dumb about this IMO. End of line means end of expression, and if you want to extend the line use a backslash. Haha, just my uninformed opinion on C and how it "should" be. revolution wrote: Okay, it is all a mystery to me, all those brackets and asterisks just to call some code are mighty confusing. |
|||
21 May 2016, 07:30 |
|
revolution 21 May 2016, 07:39
Tyler wrote: To be fair, it's not really something you should ever need to do. Semantically, OP is creating a character array and trying to "call" the contents of the array as if it were the machine code of a function. |
|||
21 May 2016, 07:39 |
|
Mike Gonta 21 May 2016, 22:57
kerr wrote: I use the FASM compiler to extract the binary to the gcc ompiler to use, prompt error pointer. .... Code: char buffer[] = "\xB0\x04\xB3\x01\x59\x66\xBA\x10\x00\xCD\x80\xB0\x01\xB3\x00\xCD\x80\xE8\xEA\xFF\x68\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64\x21\x0A"; int main(){ void (*buff)(); // define a function pointer variable buff = (void *)buffer; // assign the (cast) address of the buffer to it buff(); // call the buffer contents as a function } Code: jmp buffer To be perfectly correct buff should return an int and main should end with Code: return buff(); Code: int(*buff)(); O3 doesn't like the local buffer array and compiles the code as if it didn't exist, whereas when compiled with optimizations off run time code is used to populate the array. Probably better to define the array as global as I've done here. Also the stackoverflow example that revolution quoted is simpler as it doesn't involve the assignment (which O3 ignores anyway). Code: return ((int (*)(void))buffer)(); Last edited by Mike Gonta on 24 May 2016, 16:08; edited 1 time in total |
|||
21 May 2016, 22:57 |
|
kerr 24 May 2016, 04:04
Tyler wrote: Oh man, you're just missing a semicolon (at the end of your string). Lol, that's an annoying mistake to spend a lot of time fixing. Yeah I found complie program file running to error Program received signal SIGSEGV, Segmentation fault. 0xbffff30b in ?? () i want use gdb debug fasm complie file Feel powerless!gdb can not debug to fasm complie program file. this is my major headache things. _________________ I hope we will be good friends. |
|||
24 May 2016, 04:04 |
|
kerr 24 May 2016, 04:11
Mike Gonta wrote:
thank you I'm compile still wrong. The same with my ah. _________________ I hope we will be good friends. |
|||
24 May 2016, 04:11 |
|
cod3b453 24 May 2016, 17:52
If the intention is to hide asm in C then please ignore everything below
---- It's easier (and more flexible i.e. msvc 64 or other architectures) to split the asm and C parts: my.c Code: int main() { my_func(); return 0; } Code: format ELF64
public my_func
my_func:
ret Code: rm -v *.exe rm -v *.o fasm my.fasm my.fasm.o gcc -c my.c -o my.c.o gcc my.c.o my.fasm.o -o my.exe |
|||
24 May 2016, 17:52 |
|
kerr 24 May 2016, 22:58
cod3b453 wrote: If the intention is to hide asm in C then please ignore everything below Oh no, You speak This topic. _________________ I hope we will be good friends. |
|||
24 May 2016, 22:58 |
|
kerr 25 May 2016, 07:20
The problem is solved.
Code: char *buff="\xB0\x04\xB3\x01\x59\x66\xBA\x10\x00\xCD\x80\xB0\x01\xB3\x00\xCD\x80\xE8\xEA\xFF\x68\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64\x21\x0A" (*(void(*)())buff)();} this is ok! thank you ! bingo |
|||
25 May 2016, 07:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.