what is this assembly doing exactly?












0















I have an assembly code that I am reading, and there is the following part in the code:



    mov    $0x28,%esi
mov %rax,%rdi
callq <strchr@plt>
mov %rax,%rbx
test %rax,%rax
jne somewhere


I am having a bit of difficulty in this code. The first move moves 0x28 to register %esi. The second moves %rax to %rdi, and then it does strchr(char *rdi, char *esi). So, basically it returns the pointer to the first occurence after ascii 0x28, which is '('. Then last test tells me that it is testing whether or not string at rdi has a '(' character. If does not have, then test %rax, %rax will set ZeroFlags, and jne will not execute. Is my understanding correct?



One more question I have is when I try to check what exactly is in %esi after the first mov, I use the command p (char *)$esi in gdb but I get an output <error: Cannot access memory at address 0x28>. Could anyone advise me how I can view contents of $esi?










share|improve this question


















  • 2





    Yes you got it correct. esi holds the character itself not a pointer to it. You can do p (char)$esi or p/c $esi.

    – Jester
    Nov 21 '18 at 20:15






  • 2





    It would be more like strchr(char *rdi, int esi). Also the fact esi is not a pointer is implicit, esi is only 32-bit.

    – Havenard
    Nov 21 '18 at 20:31


















0















I have an assembly code that I am reading, and there is the following part in the code:



    mov    $0x28,%esi
mov %rax,%rdi
callq <strchr@plt>
mov %rax,%rbx
test %rax,%rax
jne somewhere


I am having a bit of difficulty in this code. The first move moves 0x28 to register %esi. The second moves %rax to %rdi, and then it does strchr(char *rdi, char *esi). So, basically it returns the pointer to the first occurence after ascii 0x28, which is '('. Then last test tells me that it is testing whether or not string at rdi has a '(' character. If does not have, then test %rax, %rax will set ZeroFlags, and jne will not execute. Is my understanding correct?



One more question I have is when I try to check what exactly is in %esi after the first mov, I use the command p (char *)$esi in gdb but I get an output <error: Cannot access memory at address 0x28>. Could anyone advise me how I can view contents of $esi?










share|improve this question


















  • 2





    Yes you got it correct. esi holds the character itself not a pointer to it. You can do p (char)$esi or p/c $esi.

    – Jester
    Nov 21 '18 at 20:15






  • 2





    It would be more like strchr(char *rdi, int esi). Also the fact esi is not a pointer is implicit, esi is only 32-bit.

    – Havenard
    Nov 21 '18 at 20:31
















0












0








0








I have an assembly code that I am reading, and there is the following part in the code:



    mov    $0x28,%esi
mov %rax,%rdi
callq <strchr@plt>
mov %rax,%rbx
test %rax,%rax
jne somewhere


I am having a bit of difficulty in this code. The first move moves 0x28 to register %esi. The second moves %rax to %rdi, and then it does strchr(char *rdi, char *esi). So, basically it returns the pointer to the first occurence after ascii 0x28, which is '('. Then last test tells me that it is testing whether or not string at rdi has a '(' character. If does not have, then test %rax, %rax will set ZeroFlags, and jne will not execute. Is my understanding correct?



One more question I have is when I try to check what exactly is in %esi after the first mov, I use the command p (char *)$esi in gdb but I get an output <error: Cannot access memory at address 0x28>. Could anyone advise me how I can view contents of $esi?










share|improve this question














I have an assembly code that I am reading, and there is the following part in the code:



    mov    $0x28,%esi
mov %rax,%rdi
callq <strchr@plt>
mov %rax,%rbx
test %rax,%rax
jne somewhere


I am having a bit of difficulty in this code. The first move moves 0x28 to register %esi. The second moves %rax to %rdi, and then it does strchr(char *rdi, char *esi). So, basically it returns the pointer to the first occurence after ascii 0x28, which is '('. Then last test tells me that it is testing whether or not string at rdi has a '(' character. If does not have, then test %rax, %rax will set ZeroFlags, and jne will not execute. Is my understanding correct?



One more question I have is when I try to check what exactly is in %esi after the first mov, I use the command p (char *)$esi in gdb but I get an output <error: Cannot access memory at address 0x28>. Could anyone advise me how I can view contents of $esi?







c assembly gdb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 20:13









dipankardipankar

294




294








  • 2





    Yes you got it correct. esi holds the character itself not a pointer to it. You can do p (char)$esi or p/c $esi.

    – Jester
    Nov 21 '18 at 20:15






  • 2





    It would be more like strchr(char *rdi, int esi). Also the fact esi is not a pointer is implicit, esi is only 32-bit.

    – Havenard
    Nov 21 '18 at 20:31
















  • 2





    Yes you got it correct. esi holds the character itself not a pointer to it. You can do p (char)$esi or p/c $esi.

    – Jester
    Nov 21 '18 at 20:15






  • 2





    It would be more like strchr(char *rdi, int esi). Also the fact esi is not a pointer is implicit, esi is only 32-bit.

    – Havenard
    Nov 21 '18 at 20:31










2




2





Yes you got it correct. esi holds the character itself not a pointer to it. You can do p (char)$esi or p/c $esi.

– Jester
Nov 21 '18 at 20:15





Yes you got it correct. esi holds the character itself not a pointer to it. You can do p (char)$esi or p/c $esi.

– Jester
Nov 21 '18 at 20:15




2




2





It would be more like strchr(char *rdi, int esi). Also the fact esi is not a pointer is implicit, esi is only 32-bit.

– Havenard
Nov 21 '18 at 20:31







It would be more like strchr(char *rdi, int esi). Also the fact esi is not a pointer is implicit, esi is only 32-bit.

– Havenard
Nov 21 '18 at 20:31














0






active

oldest

votes











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/3.0/"u003ecc by-sa 3.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%2f53419810%2fwhat-is-this-assembly-doing-exactly%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53419810%2fwhat-is-this-assembly-doing-exactly%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

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen