-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from asdetycv1zzc/master
- Loading branch information
Showing
10 changed files
with
393 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
################################################################################ | ||
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 | ||
################################################################################ | ||
|
||
/.vs | ||
/out/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "x64-Debug", | ||
"generator": "Ninja", | ||
"configurationType": "Debug", | ||
"inheritEnvironments": [ "msvc_x64_x64" ], | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"buildCommandArgs": "", | ||
"ctestCommandArgs": "" | ||
}, | ||
{ | ||
"name": "x64-Release", | ||
"generator": "Ninja", | ||
"configurationType": "Release", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"buildCommandArgs": "", | ||
"ctestCommandArgs": "", | ||
"inheritEnvironments": [ "msvc_x64_x64" ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#include<vector> | ||
#include<memory> | ||
#include"MemoryStream.h" | ||
|
||
using namespace std; | ||
|
||
BYTE* MemoryStream::GetBase() | ||
{ | ||
return _base.get(); | ||
} | ||
const uint MemoryStream::GetPosition() const | ||
{ | ||
return Position; | ||
} | ||
const size_t MemoryStream::GetSize() const | ||
{ | ||
return Length; | ||
} | ||
const BYTE* MemoryStream::GetBase() const | ||
{ | ||
return _base.get(); | ||
} | ||
BYTE* MemoryStream::GetPtr() | ||
{ | ||
return _base.get() + Position; | ||
} | ||
const BYTE* MemoryStream::GetPtr() const | ||
{ | ||
return _base.get() + Position; | ||
} | ||
|
||
void MemoryStream::Close() | ||
{ | ||
_base.reset(); | ||
} | ||
void MemoryStream::Dispose() | ||
{ | ||
Close(); | ||
} | ||
long MemoryStream::Seek(unsigned int _offset, int _Mode) | ||
{ | ||
switch (_Mode) | ||
{ | ||
case MEM_BEG: | ||
{ | ||
Position = _offset; | ||
break; | ||
} | ||
case MEM_CUR: | ||
{ | ||
Position += _offset; | ||
break; | ||
} | ||
case MEM_END: | ||
{ | ||
Position = Length - _offset; | ||
break; | ||
} | ||
default: | ||
{ | ||
break; | ||
} | ||
} | ||
return Position; | ||
} | ||
long MemoryStream::Read(vector<BYTE>& _buffer, unsigned int _size) | ||
{ | ||
Read(_buffer.data(), _size); | ||
return _size; | ||
} | ||
long MemoryStream::Read(void* _buffer, unsigned int _size) | ||
{ | ||
memcpy(_buffer, _base.get() + Position, _size); | ||
Position += _size; | ||
return _size; | ||
} | ||
template<typename _Ty> | ||
void MemoryStream::Write(const vector<_Ty>& _source) | ||
{ | ||
Write(_source.data(), _source.size()); | ||
} | ||
template<typename _Ty> | ||
void MemoryStream::Write(size_t _Pos, const _Ty* _Src, size_t _Size) | ||
{ | ||
if (Position + _Size * sizeof(_Ty) / sizeof(BYTE) > Length) return; | ||
memcpy(_base.get() + _Pos, _Src, _Size * sizeof(_Ty) / sizeof(BYTE)); | ||
Position += _Size; | ||
} | ||
template<typename _Ty> | ||
void MemoryStream::Write(const _Ty* _Src, size_t _Size) | ||
{ | ||
Write(Position, (BYTE*)_Src, _Size); | ||
} | ||
void MemoryStream::Write(const MemoryStream& _Src) | ||
{ | ||
Write(Position, _Src.GetBase(), _Src.Length); | ||
} | ||
void MemoryStream::Write(const MemoryStream* _Src) | ||
{ | ||
Write(*(_Src)); | ||
} | ||
void MemoryStream::Write(const char* _Src, size_t _Size) | ||
{ | ||
Write(Position, (BYTE*)_Src, _Size); | ||
} | ||
void MemoryStream::Write(const unsigned int* _Src, size_t _Size) | ||
{ | ||
Write(Position, (BYTE*)_Src, _Size); | ||
} | ||
void MemoryStream::Write(const int _Val, size_t _Size) | ||
{ | ||
const BYTE* _Ptr = (BYTE*)&_Val; | ||
for (size_t i = 0; i < _Size; i++) | ||
{ | ||
Write(_Ptr, sizeof(BYTE)); | ||
} | ||
} | ||
MemoryStream::MemoryStream(BYTE* _Ptr, unsigned int _size) | ||
{ | ||
Position = 0; | ||
Length = _size; | ||
_base = std::unique_ptr<BYTE>(_Ptr); | ||
} | ||
MemoryStream::MemoryStream(const vector<BYTE>& _source) | ||
{ | ||
std::unique_ptr<BYTE> _real(new BYTE[_source.size()]); | ||
Length = _source.size(); | ||
Position = 0; | ||
memcpy(_real.get(), _source.data(), _source.size() * sizeof(BYTE)); | ||
_base = std::move(_real); | ||
} | ||
MemoryStream::~MemoryStream() | ||
{ | ||
this->Dispose(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
#define MEM_BEG 0 | ||
#define MEM_CUR 1 | ||
#define MEM_END 2 | ||
#include<iostream> | ||
#include<vector> | ||
#include<memory> | ||
#include"csharp_types.h" | ||
|
||
|
||
class MemoryStream | ||
{ | ||
private: | ||
std::unique_ptr<BYTE> _base; | ||
public: | ||
uint Position = 0; | ||
uint Length = 0; | ||
|
||
BYTE* GetBase(); | ||
const BYTE* GetBase() const; | ||
const uint GetPosition() const; | ||
const size_t GetSize() const; | ||
BYTE* GetPtr(); | ||
const BYTE* GetPtr() const; | ||
|
||
long Seek(unsigned int _offset, int _Mode = MEM_BEG); | ||
|
||
long Read(std::vector<BYTE>& _buffer, unsigned int _size); | ||
long Read(void* _buffer, unsigned int _size); | ||
|
||
template<typename _Ty> | ||
void Write(const std::vector<_Ty>& _source); | ||
template<typename _Ty> | ||
void Write(size_t _Pos, const _Ty* _Src, size_t _Size); | ||
template<typename _Ty> | ||
void Write(const _Ty* _Src, size_t _Size); | ||
void Write(const MemoryStream& _Src); //Similar with CopyTo(); | ||
void Write(const MemoryStream* _Src); //Similar with CopyTo(); | ||
void Write(const char* _Src, size_t _Size); //Special Judgement, don't know why doesn't work with template | ||
void Write(const unsigned int* _Src, size_t _Size); | ||
void Write(const int _Val, size_t _Size); //Similar with memset(), Param _Val only receives int and will be converted to BYTE; | ||
|
||
void Insert(const size_t _offset, const std::vector<BYTE>& _source); | ||
void Insert(const size_t _offset, const void* _source, size_t _Size); | ||
|
||
void Erase(const size_t _offset, size_t _Size); | ||
|
||
MemoryStream(BYTE* _Ptr, unsigned int _size); | ||
MemoryStream(const std::vector<BYTE>& _source); | ||
~MemoryStream(); | ||
void Close(); | ||
void Dispose(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include<iostream> | ||
#include<fstream> | ||
#include<vector> | ||
#include<map> | ||
#include<Windows.h> | ||
|
||
typedef unsigned int uint; | ||
typedef unsigned long ulong; | ||
typedef unsigned short ushort; |
Oops, something went wrong.