From 9f8d2a75ecfc313d986dfd8678e8df07ca9b4d98 Mon Sep 17 00:00:00 2001 From: OugonNoHane Date: Sat, 29 Oct 2022 20:06:32 +0200 Subject: [PATCH] NW triple null horror --- main.cpp | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 03123db..d228b47 100644 --- a/main.cpp +++ b/main.cpp @@ -98,17 +98,22 @@ int listDirectory(std::string path, std::vector *directoryContents){ */ int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, std::vector *dest){ + static int lmao = 0; char* nextOcurrence = strchr(volumePaths, separator); - if (nextOcurrence[0] == nextOcurrence[sizeof(TCHAR)]) return 0; - + //TODO Test de cadena original + char* itemPath; itemPath = (char*)calloc(1, volumePathsBufferSize); - for (int i = 0; &volumePaths[i] == nextOcurrence; i++) { + //for (int i = 0; &volumePaths[i] == nextOcurrence; i++) { + for (int i = 0; volumePaths[i] != nextOcurrence[0]; i++) { itemPath[i] = volumePaths[i]; } dest->push_back(itemPath); - - + //TODO Test de recursividad + //if (debug) { std::cout << dest->at(0) << std::endl; exit(1); } + if (debug && lmao == 3) { std::cout << volumePaths << std::endl; exit(1); } + lmao++; + if (nextOcurrence[0] == nextOcurrence[sizeof(TCHAR)]) return 0; return explodePaths(nextOcurrence, volumePathsBufferSize, separator, dest); } @@ -116,7 +121,7 @@ int explodePaths(TCHAR* volumePaths, int volumePathsBufferSize, char separator, int listVolumes(std::vector *onPresentPaths){ //int listVolumes(){ HANDLE hFind = INVALID_HANDLE_VALUE; - char separator = '\0'; + const char separator = '\0'; int numVolumes = 0; //Volume name @@ -126,7 +131,14 @@ int listVolumes(std::vector *onPresentPaths){ int volumePathsBufferSize = (MAX_PATH + 1) * sizeof(TCHAR); unsigned long volumePathLength; TCHAR volumePaths[volumePathsBufferSize]; - + //TODO BORRAR + std::fill(volumePaths, volumePaths + volumePathsBufferSize, '4'); + for (int i = 0; i < volumePathsBufferSize; i++){ + std::cout << std::to_string(i) + ": "; + std::cout << volumePaths[i]; + std::cout << " | "; + } + std::cout << std::endl << "I IA" << std::endl; hFind = FindFirstVolume(volumeName, volumeNameSize); //if (debug) std::cout << volumeNameSize << std::endl; @@ -139,6 +151,17 @@ int listVolumes(std::vector *onPresentPaths){ if (volumePathLength == 1) { if (debug) std::cout << "Skill Issue" << std::endl; continue; } if (debug) std::cout << volumeName; if (debug) { + if (debug && volumePaths[0] == 'E') { + std::cout << volumePathLength << std::endl; + /*exit(1);*/ + for (int i = 0; i < volumePathsBufferSize; i++){ + std::cout << std::to_string(i) + ": "; + std::cout << volumePaths[i]; + std::cout << " | "; + } + std::cout << std::endl << "I IA" << std::endl; + exit(1); + } if(explodePaths(volumePaths, volumePathsBufferSize, separator, onPresentPaths)){ if (debug) std::cout << volumePaths << std::endl; for (int i = 0; i < onPresentPaths->size(); i++){