Can't get Mach-O text segment size in iOS executableiPhone executable (MACH-O) decryptionHow to get the size of symbols in the symbol table of Mach-O file?thread 1: signal SIGABRT error app crashesTrying to send mail and app crashedSelected cell not persisting in UICollectionView. Cannot save. *** Terminating app due to uncaught exceptionreact-native FBSDK LoginManager not workingFat Mach-O Executable Multi-purpose?Objective-c deallocated when opening a new form?Smallest size of valid executable Mach-o fileHow to inspect a MacOS executable file (Mach-O)?

Manager manipulates my leaves, what's in it for him?

Can Northern Ireland's border issue be solved by repartition?

Is the Necromancer's "Half-Formed Golem" pet available for all classes?

Install specific version and arch, without specifying the release

Is there any reason nowadays to use a neon indicator lamp instead of an LED?

Are there hydrocarbons on the Moon?

GitHub repo with Apache License version 2 in package.json, but no full license copy nor comment headers

What is a Heptagon Number™?

Which museums have artworks of all four ninja turtles' namesakes?

Simulate a 1D Game-of-Life-ish Model

How do rulers get rich from war?

What is the need of methods like GET and POST in the HTTP protocol?

How to create a grid following points in QGIS?

Is there an in-universe reason Harry says this or is this simply a Rowling mistake?

What informations can we obtain with these voltage and current measurements of a little electronic device?

Could someone please show me the steps of this sum?

As an employer, can I compel my employees to vote?

Create a magic square of 4-digit numbers

Social leper versus social leopard

Paradox regarding phase transitions in relativistic systems

Is it true that, "just ten trading days represent 63 per cent of the returns of the past 50 years"?

How to fix folder structure in Windows 7 and 10

Should the pagination be reset when changing the order?

Are actors contractually obligated to certain things like going nude/ Sensual Scenes/ Gory Scenes?



Can't get Mach-O text segment size in iOS executable


iPhone executable (MACH-O) decryptionHow to get the size of symbols in the symbol table of Mach-O file?thread 1: signal SIGABRT error app crashesTrying to send mail and app crashedSelected cell not persisting in UICollectionView. Cannot save. *** Terminating app due to uncaught exceptionreact-native FBSDK LoginManager not workingFat Mach-O Executable Multi-purpose?Objective-c deallocated when opening a new form?Smallest size of valid executable Mach-o fileHow to inspect a MacOS executable file (Mach-O)?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm trying to get .text segment size of Mach-O executable of my iOS app.



size_t size_of_image(struct mach_header *header) 
size_t sz = sizeof(*header); // Size of the header
sz += header->sizeofcmds; // Size of the load commands

struct load_command *lc = (struct load_command *) (header + 1);
for (uint32_t i = 0; i < header->ncmds; i++)
if (lc->cmd == LC_SEGMENT_64)
sz += ((struct segment_command *) lc)->vmsize; // Size of segments

lc = (struct load_command *) ((char *) lc + lc->cmdsize);

return sz;



and i call this function from main



int main(int argc, char * argv[]) dlinfo.dli_fbase == NULL)
return 0; // Can't find symbol for main
//
header = dlinfo.dli_fbase; // Pointer on the Mach-O header
size_of_image(header);
@autoreleasepool
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));




Problem is lc->cmd is always 0, and i never get LC_SEGMENT_64 command.



I've tried LC_SEGMENT - same result



Running iOS 12 on iPhone 6.
I need to get the .text segment of the executable for reverse - engineering protection functions.



It seems my ** mach_header *header** is wrongly field by dladdr function.



Any ideas what is wrong?










share|improve this question
























  • Hello Andrew, did you manage to solve this? I am having the same issue.

    – Agustin Pazos
    Jul 12 at 14:54











  • see answer below. it worked for me @AgustinPazos

    – Andrew
    Jul 17 at 10:56

















3















I'm trying to get .text segment size of Mach-O executable of my iOS app.



size_t size_of_image(struct mach_header *header) 
size_t sz = sizeof(*header); // Size of the header
sz += header->sizeofcmds; // Size of the load commands

struct load_command *lc = (struct load_command *) (header + 1);
for (uint32_t i = 0; i < header->ncmds; i++)
if (lc->cmd == LC_SEGMENT_64)
sz += ((struct segment_command *) lc)->vmsize; // Size of segments

lc = (struct load_command *) ((char *) lc + lc->cmdsize);

return sz;



and i call this function from main



int main(int argc, char * argv[]) dlinfo.dli_fbase == NULL)
return 0; // Can't find symbol for main
//
header = dlinfo.dli_fbase; // Pointer on the Mach-O header
size_of_image(header);
@autoreleasepool
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));




Problem is lc->cmd is always 0, and i never get LC_SEGMENT_64 command.



I've tried LC_SEGMENT - same result



Running iOS 12 on iPhone 6.
I need to get the .text segment of the executable for reverse - engineering protection functions.



It seems my ** mach_header *header** is wrongly field by dladdr function.



Any ideas what is wrong?










share|improve this question
























  • Hello Andrew, did you manage to solve this? I am having the same issue.

    – Agustin Pazos
    Jul 12 at 14:54











  • see answer below. it worked for me @AgustinPazos

    – Andrew
    Jul 17 at 10:56













3












3








3








I'm trying to get .text segment size of Mach-O executable of my iOS app.



size_t size_of_image(struct mach_header *header) 
size_t sz = sizeof(*header); // Size of the header
sz += header->sizeofcmds; // Size of the load commands

struct load_command *lc = (struct load_command *) (header + 1);
for (uint32_t i = 0; i < header->ncmds; i++)
if (lc->cmd == LC_SEGMENT_64)
sz += ((struct segment_command *) lc)->vmsize; // Size of segments

lc = (struct load_command *) ((char *) lc + lc->cmdsize);

return sz;



and i call this function from main



int main(int argc, char * argv[]) dlinfo.dli_fbase == NULL)
return 0; // Can't find symbol for main
//
header = dlinfo.dli_fbase; // Pointer on the Mach-O header
size_of_image(header);
@autoreleasepool
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));




Problem is lc->cmd is always 0, and i never get LC_SEGMENT_64 command.



I've tried LC_SEGMENT - same result



Running iOS 12 on iPhone 6.
I need to get the .text segment of the executable for reverse - engineering protection functions.



It seems my ** mach_header *header** is wrongly field by dladdr function.



Any ideas what is wrong?










share|improve this question














I'm trying to get .text segment size of Mach-O executable of my iOS app.



size_t size_of_image(struct mach_header *header) 
size_t sz = sizeof(*header); // Size of the header
sz += header->sizeofcmds; // Size of the load commands

struct load_command *lc = (struct load_command *) (header + 1);
for (uint32_t i = 0; i < header->ncmds; i++)
if (lc->cmd == LC_SEGMENT_64)
sz += ((struct segment_command *) lc)->vmsize; // Size of segments

lc = (struct load_command *) ((char *) lc + lc->cmdsize);

return sz;



and i call this function from main



int main(int argc, char * argv[]) dlinfo.dli_fbase == NULL)
return 0; // Can't find symbol for main
//
header = dlinfo.dli_fbase; // Pointer on the Mach-O header
size_of_image(header);
@autoreleasepool
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));




Problem is lc->cmd is always 0, and i never get LC_SEGMENT_64 command.



I've tried LC_SEGMENT - same result



Running iOS 12 on iPhone 6.
I need to get the .text segment of the executable for reverse - engineering protection functions.



It seems my ** mach_header *header** is wrongly field by dladdr function.



Any ideas what is wrong?







ios executable reverse-engineering segment mach-o






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 14:51









AndrewAndrew

3233 silver badges15 bronze badges




3233 silver badges15 bronze badges















  • Hello Andrew, did you manage to solve this? I am having the same issue.

    – Agustin Pazos
    Jul 12 at 14:54











  • see answer below. it worked for me @AgustinPazos

    – Andrew
    Jul 17 at 10:56

















  • Hello Andrew, did you manage to solve this? I am having the same issue.

    – Agustin Pazos
    Jul 12 at 14:54











  • see answer below. it worked for me @AgustinPazos

    – Andrew
    Jul 17 at 10:56
















Hello Andrew, did you manage to solve this? I am having the same issue.

– Agustin Pazos
Jul 12 at 14:54





Hello Andrew, did you manage to solve this? I am having the same issue.

– Agustin Pazos
Jul 12 at 14:54













see answer below. it worked for me @AgustinPazos

– Andrew
Jul 17 at 10:56





see answer below. it worked for me @AgustinPazos

– Andrew
Jul 17 at 10:56












1 Answer
1






active

oldest

votes


















2
















The culprit is in struct mach_header *header.

Replace it with struct mach_header_64 *header instead.

Keep using LC_SEGMENT_64 for modern binaries.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400596%2fcant-get-mach-o-text-segment-size-in-ios-executable%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2
















    The culprit is in struct mach_header *header.

    Replace it with struct mach_header_64 *header instead.

    Keep using LC_SEGMENT_64 for modern binaries.






    share|improve this answer





























      2
















      The culprit is in struct mach_header *header.

      Replace it with struct mach_header_64 *header instead.

      Keep using LC_SEGMENT_64 for modern binaries.






      share|improve this answer



























        2














        2










        2









        The culprit is in struct mach_header *header.

        Replace it with struct mach_header_64 *header instead.

        Keep using LC_SEGMENT_64 for modern binaries.






        share|improve this answer













        The culprit is in struct mach_header *header.

        Replace it with struct mach_header_64 *header instead.

        Keep using LC_SEGMENT_64 for modern binaries.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 15:38









        Kamil.SKamil.S

        2,4902 gold badges12 silver badges26 bronze badges




        2,4902 gold badges12 silver badges26 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400596%2fcant-get-mach-o-text-segment-size-in-ios-executable%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript