logo
down
shadow

How call and compile function from elf to my binary?


How call and compile function from elf to my binary?

By : John
Date : October 23 2020, 06:10 PM
will be helpful for those in need I have a binary file (ELF) that I don't write, but I want to use 1 function from this binary (I know the address/offset of the function), that function not exported from the binary. , I am going to answer the
code :
$ cat lib.c
int data = 42;
static int foo () { return data; }
$ nm lib.so  | grep foo
00000000000010e9 t foo
$ cat 1.c
#define _GNU_SOURCE
#include <stdio.h>
#include <link.h>
#include <string.h>
#include <elf.h>

#define FOO_VADDR 0x10e9

typedef int(*func_t)();

int callback(struct dl_phdr_info *info, size_t size, void *data)
{
    if (!(strstr(info->dlpi_name, "lib.so")))
        return 0;
    Elf64_Addr addr = info->dlpi_addr + FOO_VADDR;
    func_t f = (func_t)addr;
    int res = f();
    printf("res = %d\n", res);
    return 0;
}

int main()
{
    void *handle = dlopen("./lib.so", RTLD_LAZY);
    if (!handle) {
        puts("failed to load");
        return 1;
    }
    dl_iterate_phdr(&callback, NULL);
    dlclose(handle);
    return 0;
}
$ gcc 1.c -ldl  && ./a.out
res = 42


Share : facebook icon twitter icon
How to call a function from binary data

How to call a function from binary data


By : user1511576
Date : March 29 2020, 07:55 AM
To fix this issue I have some binary data which contains a bunch of functions and want to call one of it. I know the signature of these functions along with the offset relative to the start of the file. Calling convention is the default one: __cdecl. The file was already loaded into a memory page with executing permissions.
code :
// define a function pointer
typedef __cdecl void (*your_function) (A *arg1, B arg2, C arg3); 
your_function ftr;

char * memory = 0x123456; // base segment address

fptr = (your_function)(memory + 0x42); //calculate memory address

(*ftpr)(a,b,b); // call function
do.call-like function for binary operators in R

do.call-like function for binary operators in R


By : Romulis
Date : March 29 2020, 07:55 AM
With these it helps Is there a built-in function in R for calling binary operators/functions over a list or data frame? , For this case in particular, this would do the same trick:
code :
> apply(foo, 1, function(x) Reduce("|", x))
[1]  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE
Compile a static binary which code there a function gethostbyname

Compile a static binary which code there a function gethostbyname


By : SAM
Date : March 29 2020, 07:55 AM
may help you . What you are asking for is going to be very difficult.
See this StackOverflow question about getaddrinfo. Basically, underneath getaddrinfo/gethostbyname is glibc's NSS layer. This allows a sysadmin to say "use DNS for resolving hostnames to IP addresses", or "use LDAP", or "don't use anything other than /etc/hosts". This control is at runtime; the sysadmin can at any point change the way hostnames are resolved to IPs.
VBA Compile Error on Function Call

VBA Compile Error on Function Call


By : Mandy Torres
Date : March 29 2020, 07:55 AM
may help you . so I'm trying to run this SQL script within a function I call and it's giving me a "Compile Error: Object Required" when I try to run it!
Why does a function call missing its name still compile?

Why does a function call missing its name still compile?


By : Colby Snedeker
Date : March 29 2020, 07:55 AM
I hope this helps . A developer was copying and pasting similar types of code and made a mistake where instead of ,
Why does this line of code compile?
code :
 t.cpp:4:5: warning: left operand of comma operator has no effect [-Wunused-value]
     (x, y, z);  //What does this Line of Code do?

 t.cpp:4:8: warning: right operand of comma operator has no effect [-Wunused-value]
     (x, y, z);  //What does this Line of Code do?
Related Posts Related Posts :
  • dynamic memory for 2D char array
  • C compiler producing lightweight executeables
  • Cannot Open Shared Object cygmpfr-1.dll
  • How to access a structure member in a function that get it as void* type?
  • Replace for loop with formula
  • how to find if stack increases upwards or downwards?
  • Why does my homespun sizeof operator need a char* cast?
  • Setting exit status when creating core dump
  • Signal Handling in C
  • How to implement B+ Tree for file systems?
  • Stack storage at function call
  • Manipulate the Clipboard in C on Mac OS X
  • Problem with writing a hexadecimal string
  • Why does this code read all ' ' for the anything after the 4th character?
  • GUI for linux c
  • Where do I put all these function-like #defines, in C?
  • Padding in 24-bits rgb bitmap
  • how to acess and change variable of kernel space from user space
  • Can a conforming C implementation #define NULL to be something wacky
  • send() always interrupted by EPIPE
  • Socket Select with empty fd set
  • Coding self similar fractals in computer graphics using C
  • Forking with Pipes
  • sscanf + c99 not working on some platforms?
  • Problem with C function of type char pointer, can someone explain?
  • Macros in C.... please give the solution
  • Unix Piping using Fork and Dup
  • Any difference between these two while loops?
  • Hashtable implementation for C
  • Problems with Linked List in C
  • Stack Allocation in C
  • Random function stuck on one number
  • printf following zeros to a certain degree
  • Measuring CPU clocks consumed by a process
  • How is a CRC32 checksum calculated?
  • Tips on redefining a register bitfield in C
  • Converting a program from c to bash script
  • Static library not included in resulting LLVM executable
  • What is the meaning of "wild pointer" in C?
  • Reading DWORD from binary file
  • Efficient way to find divisibility
  • Whats the fastest, portable way to hash pointers we know are pointer aligned to a fixed size int?
  • Why does my summation program behaves weird?
  • How to determine values saved on the stack?
  • Thread scheduling C
  • C - converting to 2s complement
  • wireless networks c program
  • From where does the uboot get the information about flash, RTC, RAM in uboot/kernel development
  • printf behaviour in C
  • Measure size and way-order of L1 and L2 caches
  • Efficient copy of entire directory
  • Efficient way to create/unpack large bitfields in C?
  • getnameinfo prototype asks for sockaddr not sockaddr_in?
  • Linked List Sorting with Strings In C
  • Typecasting a floating value or using the math.h floor* functions?
  • Problem implementing sorting algorithm in C with an array of structs
  • How to copy a ram_base file to disk efficiently
  • How to fix casting a pointer to an integer?
  • How to round floating point numbers to the nearest integer in C?
  • PIC C - Sending 200 values over USB, but it only sends 25 or so of them
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk