Skip to content

Commit b9ddca2

Browse files
committed
Fix for dotnet_service then decompilation fails
- Fix for `dotnet_service` then decompilation fails - prevent infinite retry loop
1 parent 5861e77 commit b9ddca2

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

projects/dotnet_service/Controllers/DecompilerController.cs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,43 @@ public async Task<IActionResult> ProcessDecompilationRequest([FromBody] InputMes
8383
var analysisResult = _assemblyAnalysisService.AnalyzeAssembly(downloadedFilePath);
8484
_logger.LogDebug("Assembly analysis completed for: {ObjectId}", objectId);
8585

86-
// Decompile assembly
87-
outputDirectory = Path.Combine(Path.GetTempPath(), $"{objectId}_source");
88-
await _decompilerEngine.DecompileAssemblyAsync(downloadedFilePath, outputDirectory);
89-
_logger.LogDebug("File decompiled to: {outputDirectory}", outputDirectory);
90-
91-
// Create ZIP file
92-
var newObjectId = Guid.NewGuid().ToString();
93-
zipFilePath = Path.Combine(Path.GetTempPath(), newObjectId);
94-
await _decompilerEngine.CreateZipFromDirectoryAsync(outputDirectory, zipFilePath);
95-
96-
// Upload ZIP to Minio
97-
await _storageService.UploadFileAsync(zipFilePath, newObjectId);
98-
_logger.LogDebug("Zip uploaded to: {newObjectId}", newObjectId);
86+
// Attempt decompilation - this can fail for obfuscated assemblies with
87+
// illegal path characters in type/namespace names, so we handle it gracefully
88+
string decompilationObjectId = null;
89+
try
90+
{
91+
outputDirectory = Path.Combine(Path.GetTempPath(), $"{objectId}_source");
92+
await _decompilerEngine.DecompileAssemblyAsync(downloadedFilePath, outputDirectory);
93+
_logger.LogDebug("File decompiled to: {outputDirectory}", outputDirectory);
94+
95+
// Create ZIP file
96+
decompilationObjectId = Guid.NewGuid().ToString();
97+
zipFilePath = Path.Combine(Path.GetTempPath(), decompilationObjectId);
98+
await _decompilerEngine.CreateZipFromDirectoryAsync(outputDirectory, zipFilePath);
99+
100+
// Upload ZIP to Minio
101+
await _storageService.UploadFileAsync(zipFilePath, decompilationObjectId);
102+
_logger.LogDebug("Zip uploaded to: {decompilationObjectId}", decompilationObjectId);
103+
}
104+
catch (Exception decompEx)
105+
{
106+
_logger.LogWarning(decompEx, "Decompilation failed for object ID: {ObjectId}, continuing with analysis results only", objectId);
107+
decompilationObjectId = null;
108+
}
99109

100-
// Publish result with both decompilation and analysis data
110+
// Publish result with analysis data (and decompilation if it succeeded)
101111
var outputMessage = new OutputMessage
102112
{
103113
ObjectId = objectId,
104-
Decompilation = newObjectId,
114+
Decompilation = decompilationObjectId,
105115
Analysis = analysisResult
106116
};
107117

108118
await _daprClient.PublishEventAsync(PubSubName, OutputTopicName, outputMessage);
109119

110-
_logger.LogInformation("Successfully processed decompilation request and published result: {NewObjectId}", newObjectId);
120+
_logger.LogInformation("Successfully processed request for object ID: {ObjectId}, decompilation: {DecompilationSuccess}", objectId, decompilationObjectId != null);
111121

112-
return Ok(new { success = true, outputId = newObjectId, analysisResult = analysisResult });
122+
return Ok(new { success = true, outputId = decompilationObjectId, analysisResult = analysisResult });
113123
}
114124
catch (Exception ex)
115125
{

0 commit comments

Comments
 (0)