Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
Zipr Backend
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
Container Registry
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Open Source Software
Zipr Backend
Compare revisions
ef66c8c98ee8e67095e0f5f1566d9e89da5f49e0 to ac13ebc803c4ca1fa32887500fe2fe4cb520f690
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
opensrc/zipr-be
Select target project
No results found
ac13ebc803c4ca1fa32887500fe2fe4cb520f690
Select Git revision
Swap
Target
opensrc/zipr-be
Select target project
No results found
ef66c8c98ee8e67095e0f5f1566d9e89da5f49e0
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
added patching for bc1f and bc1t
· f4b53caf
Jason Hiser
authored
5 years ago
f4b53caf
some fixups for windows pgms
· ac13ebc8
Jason Hiser
authored
5 years ago
ac13ebc8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/cmdstr.hpp
+88
-0
88 additions, 0 deletions
src/cmdstr.hpp
src/ehwrite.cpp
+2
-1
2 additions, 1 deletion
src/ehwrite.cpp
src/patcher_mips32.cpp
+9
-4
9 additions, 4 deletions
src/patcher_mips32.cpp
src/pewrite.cpp
+4
-3
4 additions, 3 deletions
src/pewrite.cpp
src/zipr.cpp
+13
-8
13 additions, 8 deletions
src/zipr.cpp
with
116 additions
and
16 deletions
src/cmdstr.hpp
0 → 100644
View file @
ac13ebc8
#ifndef cmdstr_hpp
#define cmdstr_hpp
/*BINFMTCXX: -std=c++11 -Wall -Werror
*/
#include
<spawn.h>
// see manpages-posix-dev
#include
<poll.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
#include
<string.h>
#include
<sys/wait.h>
#include
<iostream>
#include
<string>
#include
<vector>
using
namespace
std
;
static
inline
pair
<
string
,
int
>
command_to_string
(
const
string
&
command
)
{
auto
ret
=
string
();
int
exit_code
=
0
;
int
cout_pipe
[
2
];
int
cerr_pipe
[
2
];
posix_spawn_file_actions_t
action
;
if
(
pipe
(
cout_pipe
)
||
pipe
(
cerr_pipe
))
cout
<<
"pipe returned an error.
\n
"
;
posix_spawn_file_actions_init
(
&
action
);
posix_spawn_file_actions_addclose
(
&
action
,
cout_pipe
[
0
]);
posix_spawn_file_actions_addclose
(
&
action
,
cerr_pipe
[
0
]);
posix_spawn_file_actions_adddup2
(
&
action
,
cout_pipe
[
1
],
1
);
posix_spawn_file_actions_adddup2
(
&
action
,
cerr_pipe
[
1
],
2
);
posix_spawn_file_actions_addclose
(
&
action
,
cout_pipe
[
1
]);
posix_spawn_file_actions_addclose
(
&
action
,
cerr_pipe
[
1
]);
// string command = "echo bla"; // example #1
// string command = "pgmcrater -width 64 -height 9 |pgmtopbm |pnmtoplainpnm";
vector
<
char
>
argsmem
[]
=
{{
's'
,
'h'
,
'\0'
},
{
'-'
,
'c'
,
'\0'
}};
// allows non-const access to literals
char
*
args
[]
=
{
&
argsmem
[
0
][
0
],
&
argsmem
[
1
][
0
],
const_cast
<
char
*>
(
command
.
c_str
()),
nullptr
};
pid_t
pid
;
if
(
posix_spawnp
(
&
pid
,
args
[
0
],
&
action
,
NULL
,
args
,
environ
)
!=
0
)
cout
<<
"posix_spawnp failed with error: "
<<
strerror
(
errno
)
<<
"
\n
"
;
close
(
cout_pipe
[
1
]),
close
(
cerr_pipe
[
1
]);
// close child-side of pipes
// Read from pipes
string
buffer
(
1024
,
' '
);
std
::
vector
<
pollfd
>
plist
=
{
{
cout_pipe
[
0
],
POLLIN
},
{
cerr_pipe
[
0
],
POLLIN
}
};
for
(
int
rval
;
(
rval
=
poll
(
&
plist
[
0
],
plist
.
size
(),
/*timeout*/
-
1
))
>
0
;
)
{
if
(
plist
[
0
].
revents
&
POLLIN
)
{
const
auto
bytes_read
=
read
(
cout_pipe
[
0
],
&
buffer
[
0
],
buffer
.
length
());
// cout << "read " << bytes_read << " bytes from stdout.\n";
// cout << buffer.substr(0, static_cast<size_t>(bytes_read)) << "\n";
ret
+=
buffer
.
substr
(
0
,
static_cast
<
size_t
>
(
bytes_read
));
}
else
if
(
plist
[
1
].
revents
&
POLLIN
)
{
const
auto
bytes_read
=
read
(
cerr_pipe
[
0
],
&
buffer
[
0
],
buffer
.
length
());
// cout << "read " << bytes_read << " bytes from stderr.\n";
// cout << buffer.substr(0, static_cast<size_t>(bytes_read)) << "\n";
ret
+=
buffer
.
substr
(
0
,
static_cast
<
size_t
>
(
bytes_read
));
}
else
break
;
// nothing left to read
}
waitpid
(
pid
,
&
exit_code
,
0
);
cout
<<
"exit code: "
<<
exit_code
<<
"
\n
"
;
posix_spawn_file_actions_destroy
(
&
action
);
return
{
ret
,
exit_code
};
}
static
inline
int
command_to_stream
(
const
string
&
command
,
ostream
&
stream
)
{
cout
<<
"Issuing command: "
<<
command
<<
endl
;
const
auto
res
=
command_to_string
(
command
);
stream
<<
res
.
first
<<
endl
;
return
res
.
second
;
}
#endif
This diff is collapsed.
Click to expand it.
src/ehwrite.cpp
View file @
ac13ebc8
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include
<zipr_dwarf2.hpp>
#include
<zipr_dwarf2.hpp>
#include
"exeio.h"
#include
"exeio.h"
#include
"cmdstr.hpp"
using
namespace
IRDB_SDK
;
using
namespace
IRDB_SDK
;
using
namespace
std
;
using
namespace
std
;
...
@@ -1506,7 +1507,7 @@ void ElfEhWriter_t<ptrsize>::CompileEhOutput()
...
@@ -1506,7 +1507,7 @@ void ElfEhWriter_t<ptrsize>::CompileEhOutput()
// create and execute the command to build the ehframe.
// create and execute the command to build the ehframe.
auto
cmd
=
(
string
)
"$PEASOUP_HOME/tools/eh_frame_tools/eh_to_bin.sh "
+
ehframe_s_filename
+
" "
+
eh_frame_hdr_addr_str
+
" "
+
ehframe_exe_filename
;
auto
cmd
=
(
string
)
"$PEASOUP_HOME/tools/eh_frame_tools/eh_to_bin.sh "
+
ehframe_s_filename
+
" "
+
eh_frame_hdr_addr_str
+
" "
+
ehframe_exe_filename
;
cout
<<
"Running: "
<<
cmd
<<
endl
;
cout
<<
"Running: "
<<
cmd
<<
endl
;
auto
res
=
system
(
cmd
.
c_str
());
auto
res
=
command_to_stream
(
cmd
,
cout
);
//
system(cmd.c_str());
// err check.
// err check.
if
(
res
==-
1
||
WEXITSTATUS
(
res
)
!=
0
)
if
(
res
==-
1
||
WEXITSTATUS
(
res
)
!=
0
)
...
...
This diff is collapsed.
Click to expand it.
src/patcher_mips32.cpp
View file @
ac13ebc8
...
@@ -64,9 +64,12 @@ void ZiprPatcherMIPS32_t::ApplyNopToPatch(RangeAddress_t addr)
...
@@ -64,9 +64,12 @@ void ZiprPatcherMIPS32_t::ApplyNopToPatch(RangeAddress_t addr)
void
ZiprPatcherMIPS32_t
::
ApplyPatch
(
RangeAddress_t
from_addr
,
RangeAddress_t
to_addr
)
void
ZiprPatcherMIPS32_t
::
ApplyPatch
(
RangeAddress_t
from_addr
,
RangeAddress_t
to_addr
)
{
{
const
auto
mask6
=
0b111111
;
const
auto
mask6
=
0b111111
;
const
auto
first_byte
=
(
uint8_t
)
memory_space
[
from_addr
+
0
];
const
auto
first_byte
=
(
uint8_t
)
memory_space
[
from_addr
+
0
];
const
auto
top6bits
=
(
first_byte
>>
2
)
&
mask6
;
const
auto
second_byte
=
(
uint8_t
)
memory_space
[
from_addr
+
1
];
const
auto
top6bits
=
(
first_byte
>>
2
)
&
mask6
;
const
auto
top16bits
=
(
uint32_t
(
first_byte
)
<<
8
)
|
second_byte
;
const
auto
top16bits_nocc
=
top16bits
&
~
(
0b11100
);
if
(
if
(
...
@@ -75,7 +78,9 @@ void ZiprPatcherMIPS32_t::ApplyPatch(RangeAddress_t from_addr, RangeAddress_t to
...
@@ -75,7 +78,9 @@ void ZiprPatcherMIPS32_t::ApplyPatch(RangeAddress_t from_addr, RangeAddress_t to
top6bits
==
0b000111
||
// bgtz,
top6bits
==
0b000111
||
// bgtz,
top6bits
==
0b000110
||
// blez,
top6bits
==
0b000110
||
// blez,
top6bits
==
0b000110
||
// blez,
top6bits
==
0b000110
||
// blez,
top6bits
==
0b000101
// bne
top6bits
==
0b000101
||
// bne
top16bits_nocc
==
0b0100010100000000
||
// bc1f
top16bits_nocc
==
0b0100010100000001
// bc1t
)
)
{
{
const
auto
new_offset
=
(
int32_t
)((
to_addr
)
-
(
from_addr
+
4
))
>>
2
;
const
auto
new_offset
=
(
int32_t
)((
to_addr
)
-
(
from_addr
+
4
))
>>
2
;
...
...
This diff is collapsed.
Click to expand it.
src/pewrite.cpp
View file @
ac13ebc8
...
@@ -87,8 +87,9 @@ void PeWriter<width,uintMa_t>::InitHeaders()
...
@@ -87,8 +87,9 @@ void PeWriter<width,uintMa_t>::InitHeaders()
assert
(
pebliss
);
assert
(
pebliss
);
const
auto
orig_file_full_headers_str
=
pebliss
->
get_full_headers_data
();
const
auto
orig_file_full_headers_str
=
pebliss
->
get_full_headers_data
();
const
auto
orig_file_full_headres_cstr
=
orig_file_full_headers_str
.
c_str
();
const
auto
orig_file_full_headers_cstr
=
orig_file_full_headers_str
.
c_str
();
const
auto
orig_file_standard_coff_header
=
(
standard_coff_header_t
*
)(
orig_file_full_headres_cstr
+
sizeof
(
dos_header
)
+
sizeof
(
coff_header_t
));
const
auto
coff_header_offset
=
*
reinterpret_cast
<
const
uint32_t
*>
(
orig_file_full_headers_cstr
+
0x3c
);
// coff header at header ptr at 0x3c
const
auto
orig_file_standard_coff_header
=
(
standard_coff_header_t
*
)(
orig_file_full_headers_cstr
+
coff_header_offset
+
sizeof
(
coff_header_t
));
// calculate the total size (last-first), rounded to page boundaries so that the OS can allocate that much virtual memory
// calculate the total size (last-first), rounded to page boundaries so that the OS can allocate that much virtual memory
// for this object.
// for this object.
...
@@ -146,7 +147,7 @@ void PeWriter<width,uintMa_t>::InitHeaders()
...
@@ -146,7 +147,7 @@ void PeWriter<width,uintMa_t>::InitHeaders()
(
uint32_t
)
image_size
,
// sizeof_image in memory (not including headers?)
(
uint32_t
)
image_size
,
// sizeof_image in memory (not including headers?)
0x1000
,
// sizeof_headers (OK to over estimate?)
0x1000
,
// sizeof_headers (OK to over estimate?)
0
,
// checksum ?? need to fix later
0
,
// checksum ?? need to fix later
3
,
// subsystem ?? read from input file?
pebliss
->
get_subsystem
(),
// subsystem ?? read from input file?
pebliss
->
get_dll_characteristics
(),
// dll_characteristics
pebliss
->
get_dll_characteristics
(),
// dll_characteristics
uintMa_t
(
pebliss
->
get_stack_size_reserve_64
()),
// sizeof_stack_reserve
uintMa_t
(
pebliss
->
get_stack_size_reserve_64
()),
// sizeof_stack_reserve
uintMa_t
(
pebliss
->
get_stack_size_commit_64
()),
// sizeof_stack_commit
uintMa_t
(
pebliss
->
get_stack_size_commit_64
()),
// sizeof_stack_commit
...
...
This diff is collapsed.
Click to expand it.
src/zipr.cpp
View file @
ac13ebc8
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#include
<iostream>
// std::cout
#include
<iostream>
// std::cout
#include
<string>
// std::string, std::to_string
#include
<string>
// std::string, std::to_string
#include
<fstream>
#include
<fstream>
#include
"cmdstr.hpp"
#define ALLOF(a) begin(a),end(a)
#define ALLOF(a) begin(a),end(a)
...
@@ -1922,8 +1923,8 @@ void ZiprImpl_t::OutputBinaryFile(const string &name)
...
@@ -1922,8 +1923,8 @@ void ZiprImpl_t::OutputBinaryFile(const string &name)
ew
.
reset
(
nullptr
);
// explicitly free ew as we're done with it
ew
.
reset
(
nullptr
);
// explicitly free ew as we're done with it
// change permissions on output file
// change permissions on output file
auto
chmod_cmd
=
string
(
"chmod +x "
)
+
output_filename
;
const
auto
chmod_cmd
=
string
(
"chmod +x "
)
+
output_filename
;
auto
res
=
syste
m
(
chmod_cmd
.
c_str
()
);
const
auto
res
=
command_to_strea
m
(
chmod_cmd
,
cout
);
assert
(
res
!=-
1
);
assert
(
res
!=-
1
);
}
}
...
@@ -2184,21 +2185,25 @@ void ZiprImpl_t::FixNoFallthroughs()
...
@@ -2184,21 +2185,25 @@ void ZiprImpl_t::FixNoFallthroughs()
void
ZiprImpl_t
::
FixTwoByteWithPrefix
()
void
ZiprImpl_t
::
FixTwoByteWithPrefix
()
{
{
const
auto
is_x64
=
m_firp
->
getArchitecture
()
->
getMachineType
()
==
admtX86_64
;
const
auto
is_x32
=
m_firp
->
getArchitecture
()
->
getMachineType
()
==
admtI386
;
if
(
!
is_x64
&&
!
is_x32
)
return
;
// only do this for x86 machines.
for
(
const
auto
insn
:
m_firp
->
getInstructions
())
for
(
const
auto
insn
:
m_firp
->
getInstructions
())
{
{
const
auto
d
=
DecodedInstruction_t
::
factory
(
insn
);
const
auto
d
=
DecodedInstruction_t
::
factory
(
insn
);
if
(
!
d
->
isBranch
())
continue
;
// skip non-branches
if
(
!
d
->
isBranch
())
continue
;
// skip non-branches
if
(
d
->
isReturn
())
continue
;
// skip returns
if
(
d
->
isReturn
())
continue
;
// skip returns
if
(
d
->
getOperands
().
size
()
!=
1
)
continue
;
// skip branches that have no operands or more than one
if
(
d
->
getOperands
().
size
()
!=
1
)
continue
;
// skip branches that have no operands or more than one
if
(
!
d
->
getOperand
(
0
)
->
isConstant
())
continue
;
// skip anything where the operand isn't a constant
if
(
!
d
->
getOperand
(
0
)
->
isConstant
())
continue
;
// skip anything where the operand isn't a constant
if
(
d
->
getPrefixCount
()
==
0
)
continue
;
// prevents arm instructions from being xformed.
while
(
true
)
while
(
true
)
{
{
const
auto
b
=
insn
->
getDataBits
()[
0
];
const
auto
b
=
static_cast
<
uint8_t
>
(
insn
->
getDataBits
()[
0
]
)
;
// basic prefix check
// basic prefix check
const
auto
prefixes
=
set
<
uint8_t
>
({
0x2e
,
0x3
e
,
0x64
,
0x65
,
0xf2
,
0xf3
});
const
auto
prefixes
=
set
<
uint8_t
>
({
0x2e
,
0x3
6
,
0x3e
,
0x26
,
0x64
,
0x65
,
0x2e
,
0x3e
,
0xf0
,
0xf2
,
0xf3
,
0x66
,
0x67
});
if
(
prefixes
.
find
(
b
)
!=
end
(
prefixes
))
if
(
prefixes
.
find
(
b
)
!=
end
(
prefixes
))
{
{
// remove prefix
// remove prefix
...
...
This diff is collapsed.
Click to expand it.