Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 896943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:48:40+00:00 2026-05-15T14:48:40+00:00

I understand somewhat how int a = b+abs(c) can be translated to simple assembly

  • 0

I understand somewhat how “int a = b+abs(c)” can be translated to simple assembly instructions and then translate that to some binary blob. But how can this be run and be interacted with dynamically in memory?

— edit —

I know C doesn’t have an eval feature. But what it’s compiled to does. I mean this is what makes Java like JITs, and for that matter, code injection malware possible no? For instance the abs() function is just a pointer, which could be called following the cdecl protocol. New functions should be able to be exposed through passing cdecl function pointers. What I don’t understand is how this new code can be injected at runtime.

I’m asking this more of as a longtime academic curiosity, then to most efficiently solve an actual problem.

— example —

Say I have a piece of embedded python code which is called from a native program a lot, and which also calls a native binding notify():

def add(a, b):
    notify()
    return a+b

For this to be a point in doing, the function should probably contain quite a bit more code (and way more usefull), but bear with me. A profiler (or hints from the c-bindings) has also identified that all calls are with with integers both with all parameters and return value.
This matches:

int add(int a, int b) {
    notify();
    return a + b;
}

Which could be compiled into an x86 cdecl something similar to this:

:_add
push ebp ;setting up scope
mov ebp, esp
call _notify ;or more likely by a pointer reference
mov eax, [ebp + 8]
mov edx, [ebp + 12]
add eax, edx
pop ebp
ret

Then finally assembled into a binary string. Of course one would have to implement a basic compiler for each platform to even get this far. But that problem aside, say I now have a char pointer to this valid binary x86 code. Is it somehow possible to extract a cdecl function pointer useable for the native program from this in any way?

Sorry for the unclear intent about my question

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:48:41+00:00Added an answer on May 15, 2026 at 2:48 pm

    Assuming you have the code already compiled in a memory block, and you have the address of the block, it can be casted to a function pointer:

    typedef int (*func)(int, int);
    ...
    char * compiledCode = ...;
    func f = (func) compiledCode;
    

    and then the function can be called:

    int x = f(2, 3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand how to create a virtualenv, activate that virtualenv, and then install django
I'm somewhat familiar with WCF in that I can build Web Services in VS.Net
The following simple code in Java behaves somewhat in a strange way that I
I understand that this question may seem somewhat ungrounded, but if someone knows anything
I understand how delegates and events work. I can also imagine some common scenarios
I understand that they are not supposed to be changed, this is somewhat of
I understand that: '\n' // literally the backslash character followed by the character for
I understand, from MSDN, that ClassInitialize is to mark a method that will do
I understand this is an easy question but for some reason this just isn't
I understand I can create an enum like this: public enum MyEnum { ONE(1),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.