main.cpp /* Metin2FileExtractor pushedx edxlabs

Size: px
Start display at page:

Download "main.cpp /* Metin2FileExtractor pushedx edxlabs"

Transcription

1 Downloaded from: justpaste.it/metin2_filext_source main.cpp /* Metin2FileExtractor pushedx edxlabs This program serves as a file extractor for the Metin2 data files. The EIX files are the header files and the EPK files are the data files. The data can be uncompressed, encrypted, and/or compressed. This code shows how the client performs the logic. This was a "for fun" project and done in about ~12 hours of work. I am releasing this tool and the source code to the elitepvperss' Metin2 community to help spread new knowledge. I have no immediate plans for a file editor at this time as I'm not playing the game or doing anything with it. Maybe sometime later though. */ I hope you enjoy! #define _CRT_SECURE_NO_WARNINGS #include <windows.h> #include <stdio.h> #include <string> #include <vector> #include <sstream> // Dumps a complete archive bool DumpArchive(const char * infolder, const char * name); int main(int argc, char * argv[]) system("cls"); printf("welcome to the Metin2 File Extractor!\n"); printf("this program was made by pushedx for the elitepvpers' Metin2 community.\n"); printf("this is a free tool for all to use.\n"); printf("it should work on the US/DE version files but Korea is not tested.\n"); printf("enjoy :)\n\n"); if(argc!= 3) printf("usage: Metin2FileExtractor <Path to PAK folder> <Archive title>\n"); printf("examples:\n"); printf("\tmetin2fileextractor \"C:\\Program Files\\Subagames\\Metin2\\pack\" BGM\n"); printf("\tmetin2fileextractor \"C:\\Program Files\\Subagames\\Metin2\\pack\" PC\n"); printf("\tmetin2fileextractor \"C:\\Program Files\\Metin2_Germany\\pack\" ETC\n"); printf("\tmetin2fileextractor \"C:\\Program Files\\Metin2_Germany\\pack\" root\n"); system("pause"); return -1; std::string safecheck = argv[2]; if(safecheck.find_first_of("!@#$%^&*()+=[] \\:\";\'<>?,./")!= std::string::npos) printf("error: The Archive title (%s) contains invalid characters. The program will now exit.\n", argv[2]); return -1; printf("beginning the archive dump. Please be patient while it finishes.\n\n"); bool result = DumpArchive(argv[1], argv[2]); if(result == true)

2 printf("the archive dump was successful!\n"); else printf("the archive dump was not successful.\n"); printf("thank you for using the Metin2 File Extractor!\n"); system("pause"); return 0; // The expected magic header value #define LZ_KEY 0x5A4F434D struct TEntry1 DWORD index; char filename[160]; DWORD dw1; DWORD dw2; DWORD dw3; DWORD dwsrcsize; DWORD unpackedcrc; DWORD dwfileoffset; BYTE packedtype; BYTE b2; BYTE b3; BYTE b4; ; struct TEntry2 DWORD header; DWORD decryptedblocksize; DWORD compressedblocksize; DWORD decompressedblocksize; ; struct TEntry3 DWORD header; DWORD version; DWORD filecount; ; // For decompressing (ripped from client) BYTE glzodata[] = 0xB9, 0x9E, 0xB0, 0x02, 0x6F, 0x69, 0x81, 0x05, 0x63, 0x98, 0x9B, 0x28, 0x79, 0x18, 0x1A, 0x00, ; // For decrypting (ripped from client) BYTE glzodata2[] = 0x22, 0xB8, 0xB4, 0x04, 0x64, 0xB2, 0x6E, 0x1F, 0xAE, 0xEA, 0x18, 0x00, 0xA6, 0xF6, 0xFB, 0x1C, ;

3 // Utility decompress function declspec(naked) void ASM_LZO_FUNC1() asm MOV EDX, DWORD PTR SS:[ESP + 0x08] MOV ECX, DWORD PTR SS:[ESP + 0x04] PUSH EBX PUSH EBP PUSH ESI MOV ESI, DWORD PTR SS:[ESP + 0x18] PUSH EDI MOV EAX, 0xC6EF3720 MOV EDI, 0x20 LEA EBX, DWORD PTR DS:[EBX] LABEL1: MOV EBX, EDX SHR EBX, 0x5 MOV EBP, EDX SHL EBP, 0x4 XOR EBX, EBP MOV EBP, EAX SHR EBP, 0x0B AND EBP, 0x03 MOV EBP, DWORD PTR DS:[ESI + EBP * 0x04] ADD EBP, EAX ADD EBX, EDX XOR EBX, EBP SUB ECX, EBX MOV EBX, ECX SHR EBX, 0x05 MOV EBP, ECX SHL EBP, 0x04 XOR EBX, EBP ADD EAX, 0x61C88647 MOV EBP, EAX AND EBP, 0x03 MOV EBP, DWORD PTR DS:[ESI + EBP * 0x04] ADD EBX, ECX ADD EBP, EAX XOR EBX, EBP SUB EDX, EBX DEC EDI JNZ LABEL1 MOV EAX, DWORD PTR SS:[ESP + 0x20] POP EDI POP ESI POP EBP MOV DWORD PTR DS:[EAX], EDX MOV DWORD PTR DS:[EAX + 0x04], ECX POP EBX RETN // Decompress function in the client declspec(naked) void ASM_LZO_CHECKKEY() asm MOV EAX,DWORD PTR SS:[ESP + 0x10] MOV ECX, EAX AND ECX, 0x JNG LABEL1 DEC ECX OR ECX, 0xFFFFFFF8

4 INC ECX LABEL1: JE LABEL2 SUB EAX, ECX ADD EAX, 8 MOV DWORD PTR SS:[ESP + 0x10],EAX JMP LABEL3; LABEL2: MOV DWORD PTR SS:[ESP + 0x10],EAX LABEL3: PUSH EBX MOV EBX, EAX SAR EBX, 0x03 TEST EBX, EBX JLE LABEL5 PUSH EBP //MOV EBP, lzodata MOV EBP, [ESP + 0x14] PUSH ESI //MOV ESI, indata MOV ESI, [ESP + 0x14] PUSH EDI //MOV EDI, outbuffer MOV EDI, [ESP + 0x14] LABEL4: MOV EAX,DWORD PTR DS:[ESI] MOV ECX,[ESI + 0x04] PUSH EDI PUSH EBP PUSH EAX PUSH ECX CALL ASM_LZO_FUNC1 ADD ESP, 0x10 ADD EDI, 0x08 ADD ESI, 0x08 DEC EBX JNZ LABEL4 MOV EAX,DWORD PTR SS:[ESP + 0x20] POP EDI POP ESI POP EBP LABEL5: POP EBX RET // Wrapper function to decompress data int LZObject_CheckKey(LPBYTE outbuffer, LPBYTE indata, LPBYTE lzodata, DWORD dwsize) int result = 1; asm mov edx, dwsize mov ecx, indata sub ecx, 4 mov eax, lzodata mov edi, outbuffer push edx

5 push eax push ecx push edi call ASM_LZO_CHECKKEY MOV EDX, DWORD PTR DS:[EDI] MOV EAX, LZ_KEY ADD ESP, 0x10 CMP EDX, EAX JE LABEL1 mov result, 0 LABEL1: NOP return result; // Ripped from the client via OllyDbg. It was tedious, but simple work since // you can set labels in OllyDbg for the new jump locations. declspec(naked) void ASM_LZO_DECOMPRESS() asm MOV EAX,DWORD PTR SS:[ESP+0x08] PUSH EBX MOV EBX,DWORD PTR SS:[ESP+0x14] PUSH EBP PUSH ESI MOV ESI,DWORD PTR SS:[ESP+0x10] MOV DWORD PTR DS:[EBX],0x00 PUSH EDI MOV CL,BYTE PTR DS:[ESI] LEA EBP,DWORD PTR DS:[ESI+EAX] MOV EAX,DWORD PTR SS:[ESP+0x1C] CMP CL,0x11 JBE label1 AND ECX,0xFF SUB ECX,0x11 CMP ECX,0x04 JB label2 label3: MOV DL,BYTE PTR DS:[ESI] DEC ECX JNZ label3 JMP label4 label1: XOR ECX,ECX MOV CL,BYTE PTR DS:[ESI] CMP ECX,0x10 JNB label5 TEST ECX,ECX JNZ label6 CMP BYTE PTR DS:[ESI],0x00 JNZ label7 label8: MOV DL,BYTE PTR DS:[ESI+0x01] ADD ECX,0xFF TEST DL,DL JE label8

6 label7: XOR EDX,EDX MOV DL,BYTE PTR DS:[ESI] LEA ECX,DWORD PTR DS:[ECX+EDX+0x0F] label6: MOV EDX,DWORD PTR DS:[ESI] ADD ESI,0x04 MOV DWORD PTR DS:[EAX],EDX ADD EAX,0x04 DEC ECX // Switch (cases 1..4) JE label4 CMP ECX,0x04 JB label9 label10: MOV EDX,DWORD PTR DS:[ESI] // Default case of switch 0055BACA SUB ECX,0x04 MOV DWORD PTR DS:[EAX],EDX ADD EAX,0x04 ADD ESI,0x04 CMP ECX,0x04 JNB label10 TEST ECX,ECX JBE label4 label11: MOV DL,BYTE PTR DS:[ESI] DEC ECX JNZ label11 JMP label4 label9: MOV DL,BYTE PTR DS:[ESI] // Cases 2,3,4 of switch 0055BACA DEC ECX JNZ label9 label4: XOR ECX,ECX // Case 1 of switch 0055BACA MOV CL,BYTE PTR DS:[ESI] CMP ECX,0x10 JNB label5 SHR ECX,0x02 MOV EDX,EAX SUB EDX,ECX XOR ECX,ECX MOV CL,BYTE PTR DS:[ESI] SHL ECX,0x02 SUB EDX,ECX MOV CL,BYTE PTR DS:[EDX-0x801] SUB EDX,0x0801 MOV BYTE PTR DS:[EAX],CL INC EDX lable28: MOV CL,BYTE PTR DS:[EDX] MOV BYTE PTR DS:[EAX],CL MOV DL,BYTE PTR DS:[EDX+0x01] label14: MOV CL,BYTE PTR DS:[ESI-0x02] AND ECX,0x03

7 JE label1 label2: MOV DL,BYTE PTR DS:[ESI] DEC ECX JNZ label2 XOR ECX,ECX MOV CL,BYTE PTR DS:[ESI] label5: CMP ECX,0x40 // Switch (cases 0..3F) JB label12 MOV EDX,ECX // Default case of switch label5 MOV EDI,EAX SHR EDX,0x02 AND EDX,0x07 SUB EDI,EDX XOR EDX,EDX MOV DL,BYTE PTR DS:[ESI] SHL EDX,0x03 SUB EDI,EDX DEC EDI SHR ECX,0x05 DEC ECX label25: MOV DL,BYTE PTR DS:[EDI] MOV DL,BYTE PTR DS:[EDI+0x01] INC EDI INC EDI label13: MOV DL,BYTE PTR DS:[EDI] INC EDI DEC ECX JNZ label13 JMP label14 label12: CMP ECX,0x20 JB label15 AND ECX,0x1F // Cases 20,21,22,23,24,25,26,27,28,29,2A,2B,2C,2D,2E,2F,30,31,32,33,34,35,36,37,38,39,3A,3B,3C,3D,3E,3F of switch label5 JNZ label16 CMP BYTE PTR DS:[ESI],0 JNZ label17 label18: MOV DL,BYTE PTR DS:[ESI+0x01] ADD ECX,0xFF TEST DL,DL JE label18 label17: XOR EDX,EDX MOV DL,BYTE PTR DS:[ESI] LEA ECX,DWORD PTR DS:[ECX+EDX+0x1F] label16: XOR EDX,EDX MOV EDI,EAX MOV DX,WORD PTR DS:[ESI]

8 SHR EDX,0x02 SUB EDI,EDX DEC EDI ADD ESI,0x02 JMP label19 label15: CMP ECX,0x10 JB label20 MOV EDX,ECX // Cases 10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F of switch label5 MOV EDI,EAX AND EDX,0x08 SHL EDX,0x0B SUB EDI,EDX AND ECX,0x07 JNZ label21 CMP BYTE PTR DS:[ESI],0x00 JNZ label22 label23: MOV DL,BYTE PTR DS:[ESI+0x01] ADD ECX,0xFF TEST DL,DL JE label23 label22: XOR EDX,EDX MOV DL,BYTE PTR DS:[ESI] LEA ECX,DWORD PTR DS:[ECX+EDX+0x07] label21: XOR EDX,EDX MOV DX,WORD PTR DS:[ESI] ADD ESI,0x02 SHR EDX,0x02 SUB EDI,EDX CMP EDI,EAX JE label24 SUB EDI,0x4000 label19: CMP ECX,0x06 JB label25 MOV EDX,EAX SUB EDX,EDI CMP EDX,0x04 JL label25 MOV EDX,DWORD PTR DS:[EDI] ADD EDI,0x04 MOV DWORD PTR DS:[EAX],EDX ADD EAX,0x04 SUB ECX,0x02 label26: MOV EDX,DWORD PTR DS:[EDI] SUB ECX,0x04 MOV DWORD PTR DS:[EAX],EDX ADD EAX,0x04 ADD EDI,0x04 CMP ECX,0x04 JNB label26 TEST ECX,ECX JBE label14 label27: MOV DL,BYTE PTR DS:[EDI] INC EDI DEC ECX JNZ label27 JMP label14 label20:

9 SHR ECX,0x02 // Cases 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F of switch label5 MOV EDX,EAX SUB EDX,ECX XOR ECX,ECX MOV CL,BYTE PTR DS:[ESI] SHL ECX,0x02 SUB EDX,ECX DEC EDX JMP lable28 label24: MOV ECX,DWORD PTR SS:[ESP+0x1C] SUB EAX,ECX CMP ESI,EBP MOV DWORD PTR DS:[EBX],EAX JNZ label29 POP EDI POP ESI POP EBP XOR EAX,EAX POP EBX RETN label29: SBB EAX,EAX POP EDI AND AL,0xFC POP ESI POP EBP ADD EAX, -4 POP EBX RETN // Decompress wrapper function void LZObject_Decompress(LPBYTE src, DWORD srclen, LPBYTE dst, DWORD * ptrnewlen, void * workmemory) asm MOV EDI, src MOV EAX, dst push workmemory MOV EDX, ptrnewlen push EDX MOV EDX, srclen PUSH EAX PUSH EDX ADD EDI, 4 PUSH EDI call ASM_LZO_DECOMPRESS ADD ESP, 0x14 TEST EAX, EAX JE LABEL1 INT 3 // Error, don't continue LABEL1: NOP // Tokenizes a string into a vector std::vector<std::string> TokenizeString(const std::string& str, const std::string& delim) //

10 using namespace std; vector<string> tokens; size_t p0 = 0, p1 = string::npos; while(p0!= string::npos) p1 = str.find_first_of(delim, p0); if(p1!= p0) string token = str.substr(p0, p1 - p0); tokens.push_back(token); p0 = str.find_first_not_of(delim, p1); return tokens; // Saves the file to a specific folder based on the path. The root // directory I choose to use is named 'output'. void SaveFile(const char * originalfilename, LPBYTE outbuffer, DWORD outbuffersize) std::stringstream dirpath; std::vector<std::string> pathtokens = TokenizeString(originalFilename, "\\/"); dirpath << "output"; CreateDirectoryA(dirPath.str().c_str(), NULL); dirpath << "\\"; size_t index = 0; for(index = 0; index < pathtokens.size() - 1; ++index) if(pathtokens[index].find_first_of(":")!= std::string::npos) continue; dirpath << pathtokens[index]; CreateDirectoryA(dirPath.str().c_str(), NULL); dirpath << "\\"; dirpath << pathtokens[index]; FILE * of = fopen(dirpath.str().c_str(), "wb"); if(of) fwrite(outbuffer, 1, outbuffersize, of); fclose(of); else printf("could not save the file %s\n", dirpath.str().c_str()); // Dumps a complete archive. I have combined two sets of logic for this, // but you can separate them if you want a more unique tool that allows // you to extract individual files or explore the contents. bool DumpArchive(const char * infolder, const char * name) HANDLE eixhandle = INVALID_HANDLE_VALUE; HANDLE epkhandle = INVALID_HANDLE_VALUE; SECURITY_ATTRIBUTES eixsecurity = 0; SECURITY_ATTRIBUTES epksecurity = 0; DWORD eixfilesize = 0; DWORD epkfilesize = 0; HANDLE eixfilemapping = NULL; HANDLE epkfilemapping = NULL;

11 LPBYTE eixfilebufferptr = NULL; LPBYTE epkfilebufferptr = NULL; bool bwaserror = false; std::string eixname_ = infolder; if(!(eixname_[eixname_.size() - 1] == '\\' eixname_[eixname_.size() - 1] == '/')) eixname_ += "\\"; eixname_ += name; eixname_ += ".eix"; std::string epkname_ = infolder; if(!(epkname_[epkname_.size() - 1] == '\\' epkname_[epkname_.size() - 1] == '/')) epkname_ += "\\"; epkname_ += name; epkname_ += ".epk"; const char * eixname = eixname_.c_str(); const char * epkname = epkname_.c_str(); eixsecurity.nlength = sizeof(security_attributes); eixsecurity.binherithandle = TRUE; eixsecurity.lpsecuritydescriptor = NULL; epksecurity.nlength = sizeof(security_attributes); epksecurity.binherithandle = TRUE; epksecurity.lpsecuritydescriptor = NULL; // Open the files to access while(bwaserror == false) eixhandle = CreateFileA(eixName, GENERIC_READ, FILE_SHARE_READ, &eixsecurity, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(eixhandle == INVALID_HANDLE_VALUE) printf("could not open the %s file. The program will now exit.\n", eixname); epkhandle = CreateFileA(epkName, GENERIC_READ, FILE_SHARE_READ, &epksecurity, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(epkhandle == INVALID_HANDLE_VALUE) printf("could not open the %s file. The program will now exit.\n", epkname); // All done now // Create the access handles for reading the files while(bwaserror == false) // We need to store the size of the file for file mapping eixfilesize = GetFileSize(eixHandle, NULL); if(eixfilesize == INVALID_FILE_SIZE) DWORD dwerror = GetLastError(); if(dwerror!= NO_ERROR) printf("there was an error [%i] getting the file size of the %s file. The program will now exit.\n", dwerror, eixname);

12 // We need to store the size of the file for file mapping epkfilesize = GetFileSize(epkHandle, NULL); if(epkfilesize == INVALID_FILE_SIZE) DWORD dwerror = GetLastError(); if(dwerror!= NO_ERROR) printf("there was an error [%i] getting the file size of the %s file. The program will now exit.\n", dwerror, epkname); // Create a file mapping object eixfilemapping = CreateFileMapping(eixHandle, NULL, PAGE_READONLY, 0, eixfilesize, NULL); if(eixfilemapping == 0) printf("could not create a file mapping object for the %s file. The program will now exit.\n", eixname); // Create a file mapping object epkfilemapping = CreateFileMapping(epkHandle, NULL, PAGE_READONLY, 0, epkfilesize, NULL); if(epkfilemapping == 0) printf("could not create a file mapping object for the %s file. The program will now exit.\n", epkname); // Create a file mapping view eixfilebufferptr = reinterpret_cast<lpbyte>(mapviewoffile(eixfilemapping, FILE_MAP_READ, 0, 0, eixfilesize)); if(eixfilebufferptr == 0) printf("could not create a view of the the %s file. The program will now exit.\n", eixname); // Create a file mapping view epkfilebufferptr = reinterpret_cast<lpbyte>(mapviewoffile(epkfilemapping, FILE_MAP_READ, 0, 0, epkfilesize)); if(epkfilebufferptr == 0) printf("could not create a view of the the %s file. The program will now exit.\n", epkname); // All done now // Now we need to verify the files we just loaded while(bwaserror == false) // We need at least 12 bytes if(eixfilesize < 0x0C) printf("the file size for the %s file is too small. The program will now exit.\n", eixname);

13 // Verify the header LPDWORD eixheader = reinterpret_cast<lpdword>(eixfilebufferptr); if(*eixheader!= 0x444B5045) // Some hard coded check // Important: This value is read from the client itself. If the client updates, this value // would need to be updated as well if it ever changed. if(*eixheader!= LZ_KEY) printf("the file header for the %s file is incorrect. The program will now exit.\n", eixname); // Get a file header pointer from the buffer TEntry2 * eixheader = (TEntry2 *)eixfilebufferptr; // Store a pointer to the encrypted data LPBYTE eixdatabuffer = eixfilebufferptr + 0x14; // We don't care about this check because we will create the // buffers ourselves in dynamic memory. The game wants to be as // efficient as possible though. if(eixheader->decompressedblocksize <= 0x10000) // Allocate space for the decompressed buffer LPBYTE decompressedbuffer = new BYTE[eixHeader->decompressedBlockSize]; memset(decompressedbuffer, 0, eixheader->decompressedblocksize); // If the contents of the file are not encrypted (no test data yet) // So, not going to add the implementation at this time. if(eixheader->decryptedblocksize == 0) printf("[todo] -- eixheader of %s is not encrypted!\n", eixname); delete [] decompressedbuffer; // We don't care about this check because we will create the // buffers ourselves in dynamic memory. The game wants to be as // efficient as possible though. if(eixheader->decryptedblocksize < 0x2000) // Create a buffer to decrypt the contents of the exi header into LPBYTE compressedbuffer = new BYTE[eixHeader->decryptedBlockSize]; memset(compressedbuffer, 0, eixheader->decryptedblocksize); // Try to decrypt the data int result = LZObject_CheckKey(compressedBuffer, eixdatabuffer, glzodata, eixheader- >decryptedblocksize); if(result == 0) delete [] decompressedbuffer; delete [] compressedbuffer; printf("there was an error decrypting the data of the %s file. The program will now exit.\n", eixname);

14 // Try to decompress the data now DWORD finalsize = 0; LZObject_Decompress(compressedBuffer, eixheader->compressedblocksize, decompressedbuffer, &finalsize, 0); // Make sure the file size matches if(finalsize!= eixheader->decompressedblocksize) delete [] decompressedbuffer; delete [] compressedbuffer; printf("there was an error decompressing the data of the %s file. The program will now exit.\n", eixname); // Get a pointer to the new file header TEntry3 * entry3 = (TEntry3 *)decompressedbuffer; // Check the file version if(entry3->version!= 2) delete [] decompressedbuffer; delete [] compressedbuffer; printf("the version of the %s file is incorrect. Expected (%i) Actual (%i). The program will now exit.\n", eixname, 2, entry3->version); // Make sure we have a match in the number of entries and the expected block size if(finalsize!= (((entry3->filecount + entry3->filecount * 2) << 0x06) + 0x0C)) delete [] decompressedbuffer; delete [] compressedbuffer; printf("the pack index file size of the %s file is incorrect. The program will now exit.\n", eixname); // Store a pointer to the block of data LPBYTE decompressedblock = decompressedbuffer + 0x0C; // If we have files to process if(entry3->filecount > 0) // Build a filename for our dump file std::string dumpfilename = eixname; dumpfilename = dumpfilename.substr(1 + dumpfilename.find_last_of("\\/")); dumpfilename = dumpfilename.substr(0, dumpfilename.find_first_of(".")); dumpfilename += "_dump.txt"; // Create the output file for the eix header dump FILE * of = fopen(dumpfilename.c_str(), "w"); if(of == 0) printf("there was an error creating the %s file. The header data will not be dumped.\n", dumpfilename.c_str()); // Loop through all of the files for(dword x = 0; x < entry3->filecount; ++x) // Create a pointer to the file entry block TEntry1 * pentry = (TEntry1 *)decompressedblock; // Make sure there is a value here if(pentry->dw2 == 0)

15 printf("no dw2 field set for the file %s\n", pentry->filename); continue; >b4); // Simple entry dump if(of) fprintf(of, "%i. ", pentry->index); fprintf(of, "%s\n", pentry->filename); fprintf(of, "[%.8X]", pentry->dw1); fprintf(of, "[%.8X]", pentry->dw2); fprintf(of, "[%.8X]", pentry->dw3); fprintf(of, "[%.8X]", pentry->dwsrcsize); fprintf(of, "[%.8X]", pentry->unpackedcrc); fprintf(of, "[%.8X]", pentry->dwfileoffset); fprintf(of, "[%.2X %.2X %.2X %.2X]", pentry->packedtype, pentry->b2, pentry->b3, pentry- fprintf(of, "\n"); // Not compressed, no extra header if(pentry->packedtype == 0) SaveFile(pEntry->filename, epkfilebufferptr + pentry->dwfileoffset, pentry->dwsrcsize); // Header and compressed/encrypted else // Decompress if(pentry->packedtype == 1) // Calculate the data pointer to the entry data block LPBYTE pdataptr = epkfilebufferptr + pentry->dwfileoffset; // Get a pointer to the header for this block TEntry2 * pentryheader = (TEntry2*)pDataPtr; LZ_KEY, h); // Make sure the header is correct DWORD h = *(reinterpret_cast<lpdword>(pdataptr)); if(h!= LZ_KEY) printf("the header for %s is incorrect. Expected (%x) Actual (%x).\n", pentry->filename, continue; // Allocate memory for the uncompressed data LPBYTE uncompresseddata = new BYTE[pEntryHeader->decompressedBlockSize]; memset(uncompresseddata, 0, pentryheader->decompressedblocksize); // Decompress the data LZObject_Decompress(pDataPtr + 16, pentryheader->compressedblocksize, uncompresseddata, &finalsize, 0); // Make sure the operation went right if(finalsize!= pentryheader->decompressedblocksize) printf("file size for %s differs from expected. Expected (%i) Actual (%i).\n", pentry- >filename, pentryheader->decompressedblocksize, finalsize); else SaveFile(pEntry->filename, uncompresseddata, pentryheader- >decompressedblocksize);

16 // Cleanup now delete [] uncompresseddata; // Decrypt + Decompress else if(pentry->packedtype == 2) // Calculate the data pointer to the entry data block LPBYTE pdataptr = epkfilebufferptr + pentry->dwfileoffset; // Get a pointer to the header for this block TEntry2 * pentryheader = (TEntry2*)pDataPtr; LZ_KEY, h); DWORD h = *(reinterpret_cast<lpdword>(pdataptr)); if(h!= LZ_KEY) printf("the header for %s is incorrect. Expected (%x) Actual (%x).\n", pentry->filename, continue; // Create a buffer for the decrypted data LPBYTE decrypteddata = new BYTE[pEntryHeader->decryptedBlockSize]; memset(decrypteddata, 0, pentryheader->decryptedblocksize); // Decrypt the data int result = LZObject_CheckKey(decryptedData, pdataptr + 20, glzodata2, pentryheader- >decryptedblocksize); if(result == 0) printf("there was an error decrypting the data for the %s file. It will be skipped.\n", pentry->filename); delete [] decrypteddata; continue; // Create a buffer for the final uncompressed data LPBYTE uncompresseddata = new BYTE[pEntryHeader->decompressedBlockSize]; memset(uncompresseddata, 0, pentryheader->decompressedblocksize); // Decompress LZObject_Decompress(decryptedData, pentryheader->compressedblocksize, uncompresseddata, &finalsize, 0); // Make sure the file sizes match if(finalsize!= pentryheader->decompressedblocksize) printf("file size for %s differs from expected. Expected (%i) Actual (%i)\n", pentry- >filename, pentryheader->decompressedblocksize, finalsize); else SaveFile(pEntry->filename, uncompresseddata, pentryheader- >decompressedblocksize); // Cleanup now delete [] decrypteddata; delete [] uncompresseddata; decompressedblock += 0xC0; // next block // Close our output file for the header dump file if(of) fclose(of);

17 // Cleanup delete [] decompressedbuffer; delete [] compressedbuffer; else // If we get here, we are using an unsupported type of file that // was not accessible at the time this tool was written. printf("[todo] -- if(*eixheader!= 0x444B5045)\n"); // All done now // Cleanup if(eixfilemapping!= 0) CloseHandle(eixFileMapping); if(epkfilemapping!= 0) CloseHandle(epkFileMapping); if(eixhandle!= INVALID_HANDLE_VALUE) CloseHandle(eixHandle); if(epkhandle!= INVALID_HANDLE_VALUE) CloseHandle(epkHandle); // Return the status return (bwaserror == false);

Data Exfiltration Techniques

Data Exfiltration Techniques Data Exfiltration Techniques Introduction In this article we will see how malware encode or encrypt data that s exfiltrated to the Command and Control Server from infected machines. This is often done

More information

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

X86 Addressing Modes Chapter 3 Review: Instructions to Recognize X86 Addressing Modes Chapter 3" Review: Instructions to Recognize" 1 Arithmetic Instructions (1)! Two Operand Instructions" ADD Dest, Src Dest = Dest + Src SUB Dest, Src Dest = Dest - Src MUL Dest, Src

More information

16.317: Microprocessor Systems Design I Fall 2014

16.317: Microprocessor Systems Design I Fall 2014 16.317: Microprocessor Systems Design I Fall 2014 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

Title: Reverse Engineering: Anti-Cracking Techniques. Date: April 12th Website:

Title: Reverse Engineering: Anti-Cracking Techniques. Date: April 12th Website: Title: Reverse Engineering: Anti-Cracking Techniques Date: April 12th 2008 Website: http://www.astalavista.com Author: Nicolaou George Mail: ishtus@astalavista.com Author: Charalambous Glafkos Mail: glafkos@astalavista.com

More information

LdPinch Report. Feng Zhu Jinpeng Wei

LdPinch Report. Feng Zhu Jinpeng Wei LdPinch Report Feng Zhu (fzhu001@fiu.edu), Jinpeng Wei (weijp@cs.fiu.edu) 1 Malware General Information Malware Name: LdPinch (named by ThreatExpert) File size: 641,536 bytes File type: PE32 executable

More information

CPS104 Recitation: Assembly Programming

CPS104 Recitation: Assembly Programming CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in

More information

Program Exploitation Intro

Program Exploitation Intro Program Exploitation Intro x86 Assembly 04//2018 Security 1 Univeristà Ca Foscari, Venezia What is Program Exploitation "Making a program do something unexpected and not planned" The right bugs can be

More information

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution 1. (40 points) Write the following subroutine in x86 assembly: Recall that: int f(int v1, int v2, int v3) { int x = v1 + v2; urn (x + v3) * (x v3); Subroutine arguments are passed on the stack, and can

More information

SA31675 / CVE

SA31675 / CVE Generated by Secunia 10 September, 2008 5 pages Table of Contents Introduction 2 Technical Details 2 Exploitation 4 Characteristics 4 Tested Versions 4 Fixed Versions 5 References 5 Generated by Secunia

More information

CSC 8400: Computer Systems. Machine-Level Representation of Programs

CSC 8400: Computer Systems. Machine-Level Representation of Programs CSC 8400: Computer Systems Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 Compilation Stages

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 21: Generating Pentium Code 10 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Simple Code Generation Three-address code makes it

More information

Computer Systems Organization V Fall 2009

Computer Systems Organization V Fall 2009 Computer Systems Organization V22.0201 Fall 2009 Sample Midterm Exam ANSWERS 1. True/False. Circle the appropriate choice. (a) T (b) F At most one operand of an x86 assembly instruction can be an memory

More information

16.317: Microprocessor Systems Design I Fall 2015

16.317: Microprocessor Systems Design I Fall 2015 16.317: Microprocessor Systems Design I Fall 2015 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs CSC 2400: Computer Systems Towards the Hardware: Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32)

More information

16.317: Microprocessor Systems Design I Spring 2015

16.317: Microprocessor Systems Design I Spring 2015 16.317: Microprocessor Systems Design I Spring 2015 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by

More information

Reverse Engineering II: The Basics

Reverse Engineering II: The Basics Reverse Engineering II: The Basics This document is only to be distributed to teachers and students of the Malware Analysis and Antivirus Technologies course and should only be used in accordance with

More information

CSE P 501 Compilers. x86 Lite for Compiler Writers Hal Perkins Autumn /25/ Hal Perkins & UW CSE J-1

CSE P 501 Compilers. x86 Lite for Compiler Writers Hal Perkins Autumn /25/ Hal Perkins & UW CSE J-1 CSE P 501 Compilers x86 Lite for Compiler Writers Hal Perkins Autumn 2011 10/25/2011 2002-11 Hal Perkins & UW CSE J-1 Agenda Learn/review x86 architecture Core 32-bit part only for now Ignore crufty, backward-compatible

More information

mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut dthiebaut@smith.edu 2 Videos to Watch at a Later Time https://www.youtube.com/watch?v=fdmzngwchdk https://www.youtube.com/watch?v=k2iz1qsx4cm

More information

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta 1 Reverse Engineering Low Level Software CS5375 Software Reverse Engineering Dr. Jaime C. Acosta Machine code 2 3 Machine code Assembly compile Machine Code disassemble 4 Machine code Assembly compile

More information

Lab 3. The Art of Assembly Language (II)

Lab 3. The Art of Assembly Language (II) Lab. The Art of Assembly Language (II) Dan Bruce, David Clark and Héctor D. Menéndez Department of Computer Science University College London October 2, 2017 License Creative Commons Share Alike Modified

More information

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing Inline Assembler Willi-Hans Steeb and Yorick Hardy International School for Scientific Computing e-mail: steebwilli@gmail.com Abstract We provide a collection of inline assembler programs. 1 Using the

More information

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

More information

Second Part of the Course

Second Part of the Course CSC 2400: Computer Systems Towards the Hardware 1 Second Part of the Course Toward the hardware High-level language (C) assembly language machine language (IA-32) 2 High-Level Language g Make programming

More information

CPEG421/621 Tutorial

CPEG421/621 Tutorial CPEG421/621 Tutorial Compiler data representation system call interface calling convention Assembler object file format object code model Linker program initialization exception handling relocation model

More information

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher Reverse Engineering II: Basics Gergely Erdélyi Senior Antivirus Researcher Agenda Very basics Intel x86 crash course Basics of C Binary Numbers Binary Numbers 1 Binary Numbers 1 0 1 1 Binary Numbers 1

More information

Inspecting and Manipulating binaries

Inspecting and Manipulating binaries Inspecting and Manipulating binaries Introduction. x86 architecture. Assembler. Binary inspection. General sample (crackme) Binary manipulation. Python to the rescue! Malware analysis What we (you) are

More information

CVE EXPLOIT USING 108 BYTES AND DOWNLOADING A FILE WITH YOUR UNLIMITED CODE BY VALTHEK

CVE EXPLOIT USING 108 BYTES AND DOWNLOADING A FILE WITH YOUR UNLIMITED CODE BY VALTHEK CVE-2017-11882 EXPLOIT USING 108 BYTES AND DOWNLOADING A FILE WITH YOUR UNLIMITED CODE BY VALTHEK First words of thank to Embedy Company to discover the initial exploit and POC of 44 bytes máximum, Ridter

More information

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer

More information

An Introduction to x86 ASM

An Introduction to x86 ASM An Introduction to x86 ASM Malware Analysis Seminar Meeting 1 Cody Cutler, Anton Burtsev Registers General purpose EAX, EBX, ECX, EDX ESI, EDI (index registers, but used as general in 32-bit protected

More information

EECE.3170: Microprocessor Systems Design I Summer 2017

EECE.3170: Microprocessor Systems Design I Summer 2017 EECE.3170: Microprocessor Systems Design I Summer 2017 Lecture 8: Key Questions June 5, 2017 1. (Review) Describe the structure of a typical x86 stack frame. EECE.3170: Microprocessor Systems Design I

More information

Reverse Engineering II: The Basics

Reverse Engineering II: The Basics Reverse Engineering II: The Basics Gergely Erdélyi Senior Manager, Anti-malware Research Protecting the irreplaceable f-secure.com Binary Numbers 1 0 1 1 - Nibble B 1 0 1 1 1 1 0 1 - Byte B D 1 0 1 1 1

More information

Autodesk AutoCAD DWG-AC1021 Heap Corruption

Autodesk AutoCAD DWG-AC1021 Heap Corruption security research Autodesk AutoCAD DWG-AC1021 Heap Corruption Mar 2013 AutoCAD is a software for computer-aided design (CAD) and technical drawing in 2D/3D, being one of the worlds leading CAD design tools.

More information

Overview of Compiler. A. Introduction

Overview of Compiler. A. Introduction CMPSC 470 Lecture 01 Topics: Overview of compiler Compiling process Structure of compiler Programming language basics Overview of Compiler A. Introduction What is compiler? What is interpreter? A very

More information

Università Ca Foscari Venezia

Università Ca Foscari Venezia Stack Overflow Security 1 2018-19 Università Ca Foscari Venezia www.dais.unive.it/~focardi secgroup.dais.unive.it Introduction Buffer overflow is due to careless programming in unsafe languages like C

More information

The geometry of innocent flesh on the bone: Return-into-libc without function calls (on the x86) Hovav Shacham presented by: Fabian Fäßler

The geometry of innocent flesh on the bone: Return-into-libc without function calls (on the x86) Hovav Shacham presented by: Fabian Fäßler The geometry of innocent flesh on the bone: Return-into-libc without function calls (on the x86) Hovav Shacham presented by: Fabian Fäßler return-oriented programming Hovav Shacham presented by: Fabian

More information

Introduction to 8086 Assembly

Introduction to 8086 Assembly Introduction to 8086 Assembly Lecture 5 Jump, Conditional Jump, Looping, Compare instructions Labels and jumping (the jmp instruction) mov eax, 1 add eax, eax jmp label1 xor eax, eax label1: sub eax, 303

More information

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Back to Conditional Jumps Review sub eax, 10 jz there xxx xxx there:yyy yyy Review cmp eax, 10 jz

More information

COMPUTER ENGINEERING DEPARTMENT

COMPUTER ENGINEERING DEPARTMENT Page 1 of 11 COMPUTER ENGINEERING DEPARTMENT December 31, 2007 COE 205 COMPUTER ORGANIZATION & ASSEMBLY PROGRAMMING Major Exam II First Semester (071) Time: 7:00 PM-9:30 PM Student Name : KEY Student ID.

More information

Basic Pentium Instructions. October 18

Basic Pentium Instructions. October 18 Basic Pentium Instructions October 18 CSC201 Section 002 Fall, 2000 The EFLAGS Register Bit 11 = Overflow Flag Bit 7 = Sign Flag Bit 6 = Zero Flag Bit 0 = Carry Flag "Sets the flags" means sets OF, ZF,

More information

Reverse Engineering For The Not So Backward

Reverse Engineering For The Not So Backward Reverse Engineering For The Not So Backward It is a Friday night and I am sitting home hyped up on caffeine and resting from a long work week. I like to relax on Friday nights and get stuff done, such

More information

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015 CS165 Computer Security Understanding low-level program execution Oct 1 st, 2015 A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns

More information

Hacking the Packer. Introduction

Hacking the Packer. Introduction Hacking the Packer I. Introduction II. Observing Code Obscurities III. Stripping Down Source Code IV. Hacking the Packer V. Producing Packed Samples VI. Possible Signature Set VII. Extended Kernel32 Resolution

More information

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated CNIT 127: Exploit Development Ch 1: Before you begin Updated 1-14-16 Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend, such as Denial

More information

CS , Fall 2009 Exam 1

CS , Fall 2009 Exam 1 Andrew login ID: Full Name: Recitation Section: CS 15-213, Fall 2009 Exam 1 Thursday, September 24, 2009 Instructions: Make sure that your exam is not missing any sheets, then write your full name, Andrew

More information

Lecture 2 Assembly Language

Lecture 2 Assembly Language Lecture 2 Assembly Language Computer and Network Security 9th of October 2017 Computer Science and Engineering Department CSE Dep, ACS, UPB Lecture 2, Assembly Language 1/37 Recap: Explorations Tools assembly

More information

mith College Computer Science CSC231 Assembly Week #10 Fall 2017 Dominique Thiébaut

mith College Computer Science CSC231 Assembly Week #10 Fall 2017 Dominique Thiébaut mith College Computer Science CSC231 Assembly Week #10 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu 2 Videos to Start With https://www.youtube.com/watch?v=fdmzngwchdk https://www.youtube.com/watch?v=k2iz1qsx4cm

More information

Buffer-Overflow Attacks on the Stack

Buffer-Overflow Attacks on the Stack Computer Systems Buffer-Overflow Attacks on the Stack Introduction A buffer overflow occurs when a program, while writing data to a buffer, overruns the buffer's boundary and overwrites memory in adjacent

More information

Architecture-level Security Vulnerabilities

Architecture-level Security Vulnerabilities Architecture-level Security Vulnerabilities Björn Döbel Outline How stacks work Smashing the stack for fun and profit Preventing stack smashing attacks Circumventing stack smashing prevention The Battlefield:

More information

CS , Spring 2004 Exam 1

CS , Spring 2004 Exam 1 Andrew login ID: Full Name: CS 15-213, Spring 2004 Exam 1 February 26, 2004 Instructions: Make sure that your exam is not missing any sheets (there should be 15), then write your full name and Andrew login

More information

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang Project 3 Questions CMSC 313 Lecture 12 How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP

More information

Subprograms: Arguments

Subprograms: Arguments Subprograms: Arguments ICS312 Machine-Level and Systems Programming Henri Casanova (henric@hawaii.edu) Activation Records The stack is useful to store and rieve urn addresses, transparently managed via

More information

COMPUTER ENGINEERING DEPARTMENT

COMPUTER ENGINEERING DEPARTMENT Page 1 of 14 COMPUTER ENGINEERING DEPARTMENT Jan. 7, 2010 COE 205 COMPUTER ORGANIZATION & ASSEMBLY PROGRAMMING Major Exam II First Semester (091) Time: 3:30 PM-6:00 PM Student Name : KEY Student ID. :

More information

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string. 1 od 5 17. 12. 2017 23:53 (https://github.com/schweigi/assembler-simulator) Introduction This simulator provides a simplified assembler syntax (based on NASM (http://www.nasm.us)) and is simulating a x86

More information

Buffer Overflow Attack

Buffer Overflow Attack Buffer Overflow Attack What every applicant for the hacker should know about the foundation of buffer overflow attacks By (Dalgona@wowhacker.org) Email: zinwon@gmail.com 2005 9 5 Abstract Buffer overflow.

More information

Buffer-Overflow Attacks on the Stack

Buffer-Overflow Attacks on the Stack Computer Systems Buffer-Overflow Attacks on the Stack Introduction A buffer overflow occurs when a program, while writing data to a buffer, overruns the buffer's boundary and overwrites memory in adjacent

More information

Sungkyunkwan University

Sungkyunkwan University - 2 - Complete addressing mode, address computation (leal) Arithmetic operations Control: Condition codes Conditional branches While loops - 3 - Most General Form D(Rb,Ri,S) Mem[ Reg[ R b ] + S Reg[ R

More information

Computer Architecture and Assembly Language. Practical Session 3

Computer Architecture and Assembly Language. Practical Session 3 Computer Architecture and Assembly Language Practical Session 3 Advanced Instructions division DIV r/m - unsigned integer division IDIV r/m - signed integer division Dividend Divisor Quotient Remainder

More information

Rev101. spritzers - CTF team. spritz.math.unipd.it/spritzers.html

Rev101. spritzers - CTF team. spritz.math.unipd.it/spritzers.html Rev101 spritzers - CTF team spritz.math.unipd.it/spritzers.html Disclaimer All information presented here has the only purpose of teaching how reverse engineering works. Use your mad skillz only in CTFs

More information

CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE351 Spring 2018, Midterm Exam April 27, 2018 CSE351 Spring 2018, Midterm Exam April 27, 2018 Please do not turn the page until 11:30. Last Name: First Name: Student ID Number: Name of person to your left: Name of person to your right: Signature indicating:

More information

printf("this program adds the value 10 to a given integer number.\n\n");

printf(this program adds the value 10 to a given integer number.\n\n); PA1 Sample Solution Program 1 void add10(int *n); //Prototype int n; printf("this program adds the value 10 to a given integer number.\n\n"); printf("please enter an integer number: "); scanf("%d", &n);

More information

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? exam on Wednesday today s material not on the exam 1 Assembly Assembly is programming

More information

Assembly Language: Function Calls

Assembly Language: Function Calls Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and returning Passing parameters Storing local variables Handling registers without interference

More information

CSE 351 Midterm Exam

CSE 351 Midterm Exam University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse February 5, 2018 CSE 351 Midterm Exam Last Name: First Name: SOLUTIONS UW Student ID Number: UW NetID (username):

More information

Return oriented programming

Return oriented programming Return oriented programming TOOR - Computer Security Hallgrímur H. Gunnarsson Reykjavík University 2012-05-04 Introduction Many countermeasures have been introduced to foil EIP hijacking: W X: Prevent

More information

Reversing Basics A Practical Approach

Reversing Basics A Practical Approach Reversing Basics A Practical Approach Author: Amit Malik (DouBle_Zer0) E-Mail: m.amit30@gmail.com Note: Keep Out of Reach of Children/Danger-Software Poison. Download EXE/Crackme: https://sites.google.com/site/hacking1now/crackmes

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"

More information

CS , Fall 2007 Exam 1

CS , Fall 2007 Exam 1 Andrew login ID: Full Name: CS 15-213, Fall 2007 Exam 1 Wednesday October 17, 2007 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the

More information

15-213/18-243, Fall 2010 Exam 1 - Version A

15-213/18-243, Fall 2010 Exam 1 - Version A Andrew login ID: Full Name: Section: 15-213/18-243, Fall 2010 Exam 1 - Version A Tuesday, September 28, 2010 Instructions: Make sure that your exam is not missing any sheets, then write your Andrew login

More information

CSCI 334: Principles of Programming Languages. Computer Architecture (a really really fast introduction) Lecture 11: Control Structures II

CSCI 334: Principles of Programming Languages. Computer Architecture (a really really fast introduction) Lecture 11: Control Structures II 1 byte{ 1 byte{ CSCI 334: Principles of Programming Languages Lecture 11: Control Structures II Computer Architecture (a really really fast introduction) Instructor: Dan Barowy Memory Instructions main

More information

Assembly Language: IA-32 Instructions

Assembly Language: IA-32 Instructions Assembly Language: IA-32 Instructions 1 Goals of this Lecture Help you learn how to: Manipulate data of various sizes Leverage more sophisticated addressing modes Use condition codes and jumps to change

More information

15-213/18-243, Spring 2011 Exam 1

15-213/18-243, Spring 2011 Exam 1 Andrew login ID: Full Name: Section: 15-213/18-243, Spring 2011 Exam 1 Thursday, March 3, 2011 (v1) Instructions: Make sure that your exam is not missing any sheets, then write your Andrew login ID, full

More information

A CRASH COURSE IN X86 DISASSEMBLY

A CRASH COURSE IN X86 DISASSEMBLY A CRASH COURSE IN X86 DISASSEMBLY As discussed in previous chapters, basic static and dynamic malware analysis methods are good for initial triage, but they do not provide enough information to analyze

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and urning" Passing parameters" Storing local variables" Handling registers without interference"

More information

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and urning Passing parameters Storing local variables Handling registers without interference Returning

More information

StarForce 3 - Brief insight into a hidden world. By [yates] [http://www.yates2k.net] [http://www.reteam.org]

StarForce 3 - Brief insight into a hidden world. By [yates] [http://www.yates2k.net] [http://www.reteam.org] StarForce 3 - Brief insight into a hidden world. By [yates] [http://www.yates2k.net] [http://www.reteam.org] These notes are intended for anyone wishing to study the working elements of this protection.

More information

Function Call Convention

Function Call Convention Function Call Convention Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona Tel +41 55 214 41 60 Fax +41 55 214 41 61 team@csnc.ch www.csnc.ch Content Intel Architecture Memory Layout

More information

Basic exploitation techniques

Basic exploitation techniques Basic exploitation techniques 20180118 Outline A primer on x86 assembly Memory segments Stack-based buffer overflows Heap-based overflow Format strings 1 A primer on x86 assembly Introduction Verily, when

More information

CS / ECE , Spring 2010 Exam 1

CS / ECE , Spring 2010 Exam 1 Andrew login ID: Full Name: Recitation Section: CS 15-213 / ECE 18-243, Spring 2010 Exam 1 Version 1100101 Tuesday, March 2nd, 2010 Instructions: Make sure that your exam is not missing any sheets, then

More information

Do not turn the page until 12:30.

Do not turn the page until 12:30. University of Washington Computer Science & Engineering Autumn 2016 Instructor: Justin Hsia 2016-12-13 Last Name: First Name: Student ID Number: Section you attend (circle): Chris Yufang John Kevin Sachin

More information

Jump instructions. Unconditional jumps Direct jump. do not change flags. jmp label

Jump instructions. Unconditional jumps Direct jump. do not change flags. jmp label do not change flags Unconditional jumps Direct jump jmp label Jump instructions jmp Continue xor eax,eax Continue: xor ecx,ecx Machine code: 0040340A EB 02 0040340C 33 C0 0040340E 33 C9 displacement =

More information

Introduction to Reverse Engineering. Alan Padilla, Ricardo Alanis, Stephen Ballenger, Luke Castro, Jake Rawlins

Introduction to Reverse Engineering. Alan Padilla, Ricardo Alanis, Stephen Ballenger, Luke Castro, Jake Rawlins Introduction to Reverse Engineering Alan Padilla, Ricardo Alanis, Stephen Ballenger, Luke Castro, Jake Rawlins Reverse Engineering (of Software) What is it? What is it for? Binary exploitation (the cool

More information

Computer Architecture and Assembly Language. Practical Session 5

Computer Architecture and Assembly Language. Practical Session 5 Computer Architecture and Assembly Language Practical Session 5 Addressing Mode - "memory address calculation mode" An addressing mode specifies how to calculate the effective memory address of an operand.

More information

Assembly Language for Intel-Based Computers, 4 th Edition. Lecture 25: Interface With High-Level Language

Assembly Language for Intel-Based Computers, 4 th Edition. Lecture 25: Interface With High-Level Language Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Lecture 25: Interface With High-Level Language Slide show prepared by Kip R. Irvine, Revision date: 07/07/2002 Modified on April

More information

Static Analysis I PAOLO PALUMBO, F-SECURE CORPORATION

Static Analysis I PAOLO PALUMBO, F-SECURE CORPORATION Static Analysis I PAOLO PALUMBO, F-SECURE CORPORATION Representing Data Binary numbers 1 0 1 1 NIBBLE 0xB 1 0 1 1 1 1 0 1 0xBD 1 0 1 1 1 1 0 1 0 0 1 1 1 0 0 1 BYTE WORD 0xBD 0x39 Endianness c9 33 41 03

More information

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10] The following pages contain references for use during the exam: tables containing the x86 instruction set (covered so far) and condition codes. You do not need to submit these pages when you finish your

More information

Process Layout and Function Calls

Process Layout and Function Calls Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized

More information

SOEN228, Winter Revision 1.2 Date: October 25,

SOEN228, Winter Revision 1.2 Date: October 25, SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003 1 Contents Flags Mnemonics Basic I/O Exercises Overview of sample programs 2 Flag Register The flag register stores the condition flags that retain

More information

The IA-32 Stack and Function Calls. CS4379/5375 Software Reverse Engineering Dr. Jaime C. Acosta

The IA-32 Stack and Function Calls. CS4379/5375 Software Reverse Engineering Dr. Jaime C. Acosta 1 The IA-32 Stack and Function Calls CS4379/5375 Software Reverse Engineering Dr. Jaime C. Acosta 2 Important Registers used with the Stack EIP: ESP: EBP: 3 Important Registers used with the Stack EIP:

More information

Do not turn the page until 5:10.

Do not turn the page until 5:10. University of Washington Computer Science & Engineering Autumn 2018 Instructor: Justin Hsia 2018-10-29 Last Name: First Name: Student ID Number: Name of person to your Left Right All work is my own. I

More information

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View Computer Architecture I Instruction Set Architecture Assembly Language View Processor state Registers, memory, Instructions addl, movl, andl, How instructions are encoded as bytes Layer of Abstraction

More information

SA30285 / CVE

SA30285 / CVE Generated by Secunia 17 December, 2008 6 pages Table of Contents Introduction 2 Technical Details 2 Exploitation 5 Characteristics 6 Tested Versions 6 Fixed Versions 6 References 6 Generated by Secunia

More information

Lecture 10 Return-oriented programming. Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller

Lecture 10 Return-oriented programming. Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller Lecture 10 Return-oriented programming Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller ROP Overview Idea: We forge shellcode out of existing application

More information

Architecture-level Security Vulnerabilities. Julian Stecklina

Architecture-level Security Vulnerabilities. Julian Stecklina Architecture-level Security Vulnerabilities Julian Stecklina Outline How stacks work Smashing the stack for fun and profit Preventing stack smashing attacks Circumventing stack smashing prevention The

More information

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today: Winter 2006-2007 Compiler Construction T11 Activation records + Introduction to x86 assembly Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University Today ic IC Language Lexical Analysis

More information

CS241 Computer Organization Spring 2015 IA

CS241 Computer Organization Spring 2015 IA CS241 Computer Organization Spring 2015 IA-32 2-10 2015 Outline! Review HW#3 and Quiz#1! More on Assembly (IA32) move instruction (mov) memory address computation arithmetic & logic instructions (add,

More information

Analyzing the packer layers of rogue anti-virus programs. Rachit Mathur, McAfee Labs Dr. Zheng Zhang, McAfee Labs

Analyzing the packer layers of rogue anti-virus programs. Rachit Mathur, McAfee Labs Dr. Zheng Zhang, McAfee Labs Analyzing the packer layers of rogue anti-virus programs Rachit Mathur, McAfee Labs Dr. Zheng Zhang, McAfee Labs Outline Introduction Junk API Calls Exception Context Modifications Shared User Data Accesses

More information

CMSC 313 Lecture 12 [draft] How C functions pass parameters

CMSC 313 Lecture 12 [draft] How C functions pass parameters CMSC 313 Lecture 12 [draft] How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP removes an

More information

Using MMX Instructions to Perform Simple Vector Operations

Using MMX Instructions to Perform Simple Vector Operations Using MMX Instructions to Perform Simple Vector Operations Information for Developers and ISVs From Intel Developer Services www.intel.com/ids Information in this document is provided in connection with

More information

In executable we have several anti-debugging, anti-tracing and anti-patching tricks:

In executable we have several anti-debugging, anti-tracing and anti-patching tricks: ------------------------------------------------------------------ Author: ReWolf e-mail: rewolf@rewolf.pl www : http://rewolf.pl ------------------------------------------------------------------ HACKER

More information

Recitation 4: Bomb Lab

Recitation 4: Bomb Lab 15-213 Recitation 4: Bomb Lab 2 Feb 2016 Monil Shah, Shelton D Souza, Ralf Brown 1 Agenda Bomb Lab Overview Assembly Refresher Introduction to GDB Bomb Lab Demo 2 Downloading Your Bomb Please read the

More information