Skip to content

Commit

Permalink
[tool] 코드 및 바이너리를 추출할 때 파일 헤더의 정보를 변경할 수 있는 옵션 추가
Browse files Browse the repository at this point in the history
코드 또는 바이너리를 추출할 때 코드에 바이너리 정보 또는 파일 헤더의 정보를 변경할 수 있다.
- 추출된 코드의 리버전 정보, 해시값을 변경
- 추출된 바이너리의 파일 헤더의 리비전, 해시값을 변경

사용예) .\cremadev.exe get <address> <path> --database Default --replace-revision 0 --replace-hashvalue 0
  • Loading branch information
powerumc committed Jun 19, 2019
1 parent c07ce40 commit d300589
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tools/Ntreev.Crema.Commands/DataSplitSetting.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
using System;
//Released under the MIT License.
//
//Copyright (c) 2018 Ntreev Soft co., Ltd.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
//persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
//Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down
3 changes: 3 additions & 0 deletions tools/Ntreev.Crema.Commands/GetCodeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ntreev.Crema.Commands.OptionProcessor;

namespace Ntreev.Crema.Commands
{
[Export(typeof(ICommand))]
[CommandStaticProperty(typeof(CodeSettings))]
[CommandStaticProperty(typeof(FilterSettings))]
[CommandStaticProperty(typeof(DataBaseSettings))]
[CommandStaticProperty(typeof(ReplaceSettings))]
class GetCodeCommand : CommandBase
{
[Import]
Expand Down Expand Up @@ -106,6 +108,7 @@ private void GenerateCode()

this.Out.WriteLine("receiving info");
var metaData = this.service.GetMetaData(this.Address, DataBaseSettings.DataBaseName, DataBaseSettings.Tags, FilterSettings.FilterExpression, CodeSettings.Devmode, this.Revision);
metaData = ReplaceOptionProcessor.Process(metaData);

var generationSettings = new CodeGenerationSettings()
{
Expand Down
3 changes: 3 additions & 0 deletions tools/Ntreev.Crema.Commands/GetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ntreev.Crema.Commands.OptionProcessor;

namespace Ntreev.Crema.Commands
{
[Export(typeof(ICommand))]
[CommandStaticProperty(typeof(CodeSettings))]
[CommandStaticProperty(typeof(FilterSettings))]
[CommandStaticProperty(typeof(DataBaseSettings))]
[CommandStaticProperty(typeof(ReplaceSettings))]
class GetCommand : CommandBase
{
[Import]
Expand Down Expand Up @@ -114,6 +116,7 @@ protected override void OnExecute()

this.Out.WriteLine("receiving info");
var metaData = this.service.GetMetaData(this.Address, DataBaseSettings.DataBaseName, DataBaseSettings.Tags, FilterSettings.FilterExpression, CodeSettings.Devmode, this.Revision);
metaData = ReplaceOptionProcessor.Process(metaData);

var generationSettings = new CodeGenerationSettings()
{
Expand Down
5 changes: 5 additions & 0 deletions tools/Ntreev.Crema.Commands/GetDataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ntreev.Crema.Commands.OptionProcessor;

namespace Ntreev.Crema.Commands
{
[Export(typeof(ICommand))]
[CommandStaticProperty(typeof(FilterSettings))]
[CommandStaticProperty(typeof(DataBaseSettings))]
[CommandStaticProperty(typeof(DataSplitSetting))]
[CommandStaticProperty(typeof(ReplaceSettings))]
class GetDataCommand : CommandBase
{
[Import]
Expand Down Expand Up @@ -104,6 +106,7 @@ protected override void OnExecute()

this.Out.WriteLine("receiving info");
var metaData = service.GetDataGenerationData(this.Address, DataBaseSettings.DataBaseName, DataBaseSettings.Tags, FilterSettings.FilterExpression, this.Devmode, this.Revision);
metaData = ReplaceOptionProcessor.Process(metaData);

this.Out.WriteLine("data serializing.");
var serializer = this.serializers.FirstOrDefault(item => item.Name == this.OutputType);
Expand Down Expand Up @@ -135,6 +138,8 @@ private void SerializePerTable(IDataSerializer serializer, SerializationSet meta
foreach (var table in metaData.Tables)
{
var filteredMetaData = metaData.Filter(table.Name);
filteredMetaData = ReplaceOptionProcessor.Process(filteredMetaData);

if (filteredMetaData.Tables.Any())
{
metaDataList.Add(filteredMetaData);
Expand Down
2 changes: 2 additions & 0 deletions tools/Ntreev.Crema.Commands/Ntreev.Crema.Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<ItemGroup>
<Compile Include="CodeSettings.cs" />
<Compile Include="DataBaseSettings.cs" />
<Compile Include="OptionProcessor\ReplaceOptionProcessor.cs" />
<Compile Include="ReplaceSettings.cs" />
<Compile Include="DataSplitSetting.cs" />
<Compile Include="FilterSettings.cs" />
<Compile Include="GetCodeCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//Released under the MIT License.
//
//Copyright (c) 2018 Ntreev Soft co., Ltd.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
//persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
//Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ntreev.Crema.Runtime.Generation;
using Ntreev.Crema.Runtime.Serialization;

namespace Ntreev.Crema.Commands.OptionProcessor
{
static class ReplaceOptionProcessor
{
public static Tuple<GenerationSet, SerializationSet> Process(Tuple<GenerationSet, SerializationSet> metaData)
{
var generationSet = metaData.Item1;
var serializationSet = metaData.Item2;

generationSet = Process(generationSet);
serializationSet = Process(serializationSet);

return new Tuple<GenerationSet, SerializationSet>(generationSet, serializationSet);
}

public static GenerationSet Process(GenerationSet generationSet)
{
if (ReplaceSettings.ReplaceHashValue != null)
{
generationSet.Revision = ReplaceSettings.ReplaceRevision;
generationSet.TablesHashValue = ReplaceSettings.ReplaceHashValue;
generationSet.TypesHashValue = ReplaceSettings.ReplaceHashValue;
}

return generationSet;
}

public static SerializationSet Process(SerializationSet serializationSet)
{
if (ReplaceSettings.ReplaceRevision != long.MinValue)
{
serializationSet.Revision = ReplaceSettings.ReplaceRevision;
serializationSet.TablesHashValue = ReplaceSettings.ReplaceHashValue;
serializationSet.TypesHashValue = ReplaceSettings.ReplaceHashValue;
}

return serializationSet;
}
}
}
46 changes: 46 additions & 0 deletions tools/Ntreev.Crema.Commands/ReplaceSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//Released under the MIT License.
//
//Copyright (c) 2018 Ntreev Soft co., Ltd.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
//persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
//Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ntreev.Library.Commands;

namespace Ntreev.Crema.Commands
{
static class ReplaceSettings
{
[CommandProperty]
[DefaultValue((long)long.MinValue)]
[Description("바이너리 파일 헤더의 Revision 값을 변경합니다.")]
public static long ReplaceRevision
{
get; set;
}

[CommandProperty("replace-hashvalue")]
[DefaultValue(null)]
[Description("바이너리 파일 헤더의 TablesHashValue, TypesHashValue 값을 변경합니다.")]
public static string ReplaceHashValue
{
get; set;
}
}
}

0 comments on commit d300589

Please sign in to comment.