Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Keystone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Third Party Mirrors
Keystone
Commits
07cef069
Commit
07cef069
authored
8 years ago
by
Remco
Browse files
Options
Downloads
Patches
Plain Diff
allow kstool input from stdin
parent
aaa7a357
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kstool/kstool.cpp
+35
-6
35 additions, 6 deletions
kstool/kstool.cpp
with
35 additions
and
6 deletions
kstool/kstool.cpp
+
35
−
6
View file @
07cef069
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
// By Nguyen Anh Quynh, 2016
// By Nguyen Anh Quynh, 2016
#include
<stdio.h>
#include
<stdio.h>
#include
<string.h>
#include
<string.h>
#include
<unistd.h>
#include
<fcntl.h>
#include
<keystone/keystone.h>
#include
<keystone/keystone.h>
...
@@ -10,7 +12,7 @@
...
@@ -10,7 +12,7 @@
static
void
usage
(
char
*
prog
)
static
void
usage
(
char
*
prog
)
{
{
printf
(
"Kstool v%s for Keystone Assembler Engine (www.keystone-engine.org)
\n
By Nguyen Anh Quynh, 2016
\n\n
"
,
VERSION
);
printf
(
"Kstool v%s for Keystone Assembler Engine (www.keystone-engine.org)
\n
By Nguyen Anh Quynh, 2016
\n\n
"
,
VERSION
);
printf
(
"Syntax: %s <arch+mode> <assembly-string>
\n
"
,
prog
);
printf
(
"Syntax: %s <arch+mode> <assembly-string>
or cat <asmfile> | %s <arch+mode>
\n
"
,
prog
,
prog
);
printf
(
"
\n
The following <arch+mode> options are supported:
\n
"
);
printf
(
"
\n
The following <arch+mode> options are supported:
\n
"
);
if
(
ks_arch_supported
(
KS_ARCH_X86
))
{
if
(
ks_arch_supported
(
KS_ARCH_X86
))
{
...
@@ -69,19 +71,43 @@ int main(int argc, char **argv)
...
@@ -69,19 +71,43 @@ int main(int argc, char **argv)
{
{
ks_engine
*
ks
;
ks_engine
*
ks
;
ks_err
err
=
KS_ERR_ARCH
;
ks_err
err
=
KS_ERR_ARCH
;
char
*
mode
,
*
assembly
;
char
*
mode
,
*
assembly
=
NULL
;
char
*
input
=
NULL
;
size_t
count
;
size_t
count
;
unsigned
char
*
insn
;
unsigned
char
*
insn
;
size_t
size
;
size_t
size
;
if
(
argc
!=
3
)
{
#ifndef LLVM_ON_WIN32
if
(
argc
==
2
)
{
mode
=
argv
[
1
];
int
flags
;
if
(
-
1
==
(
flags
=
fcntl
(
STDIN_FILENO
,
F_GETFL
,
0
)))
flags
=
0
;
fcntl
(
STDIN_FILENO
,
F_SETFL
,
flags
|
O_NONBLOCK
);
unsigned
int
index
=
0
;
char
buf
[
1024
];
while
(
fgets
(
buf
,
sizeof
(
buf
),
stdin
)
)
{
input
=
(
char
*
)
realloc
(
assembly
,
index
+
strlen
(
buf
));
memcpy
(
&
input
[
index
],
buf
,
strlen
(
buf
));
index
+=
strlen
(
buf
);
}
assembly
=
input
;
}
else
if
(
argc
==
3
)
{
#else
if
(
argc
==
3
)
{
#endif
mode
=
argv
[
1
];
assembly
=
argv
[
2
];
}
else
{
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
return
-
1
;
return
-
1
;
}
}
mode
=
argv
[
1
];
assembly
=
argv
[
2
];
if
(
!
strcmp
(
mode
,
"x16"
))
{
if
(
!
strcmp
(
mode
,
"x16"
))
{
err
=
ks_open
(
KS_ARCH_X86
,
KS_MODE_16
,
&
ks
);
err
=
ks_open
(
KS_ARCH_X86
,
KS_MODE_16
,
&
ks
);
}
}
...
@@ -227,5 +253,8 @@ int main(int argc, char **argv)
...
@@ -227,5 +253,8 @@ int main(int argc, char **argv)
// close Keystone instance when done
// close Keystone instance when done
ks_close
(
ks
);
ks_close
(
ks
);
if
(
input
)
free
(
input
);
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment