what is this assembly doing exactly?
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
add a comment |
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
2
Yes you got it correct.esi
holds the character itself not a pointer to it. You can dop (char)$esi
orp/c $esi
.
– Jester
Nov 21 '18 at 20:15
2
It would be more likestrchr(char *rdi, int esi)
. Also the factesi
is not a pointer is implicit,esi
is only 32-bit.
– Havenard
Nov 21 '18 at 20:31
add a comment |
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
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
c assembly gdb
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 dop (char)$esi
orp/c $esi
.
– Jester
Nov 21 '18 at 20:15
2
It would be more likestrchr(char *rdi, int esi)
. Also the factesi
is not a pointer is implicit,esi
is only 32-bit.
– Havenard
Nov 21 '18 at 20:31
add a comment |
2
Yes you got it correct.esi
holds the character itself not a pointer to it. You can dop (char)$esi
orp/c $esi
.
– Jester
Nov 21 '18 at 20:15
2
It would be more likestrchr(char *rdi, int esi)
. Also the factesi
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
Yes you got it correct.
esi
holds the character itself not a pointer to it. You can dop (char)$esi
orp/c $esi
.– Jester
Nov 21 '18 at 20:15
2
It would be more like
strchr(char *rdi, int esi)
. Also the factesi
is not a pointer is implicit,esi
is only 32-bit.– Havenard
Nov 21 '18 at 20:31